Datafeedr Support Forums

Datafeedr Support Forums (/index.php)
-   Questions (/forumdisplay.php?f=67)
-   -   Can I use shortcodes in a text widget? (/showthread.php?t=5189)

DogWalkingGear September 15th, 2011 12:36 PM

Can I use shortcodes in a text widget?
I would like to be able to put a product into the sidebar on some pages and I would like to use the product ID to minimise how much work is needed to change it. I have done this via a shortcode in a post or page but when I tried to use a the same shortcode in a text widget I can't get it to work - is this possible?

I followed the instructions and have this working properly if the shortcode is in a page or post, but copying the same shortcode into a text widget does not seem to work
In a post [DFR:Embedded 150 Pic Cube?p=491100198966992] displays as the image
In a widget [DFR:Embedded 150 Pic Cube?p=491100198966992] just shows as the text

I tried adding add_filter('widget_text', 'do_shortcode'); to my theme - no luck
for other plugins I have used the following to get the shortcode to work in a widget
if ( function_exists ('name-of-plugin-function-that-does-shortcode')) {
add_filter('widget_text', 'name-of-plugin-function-that-does-shortcode' );
I can't try this since I don't know the name of the function for datafeedr shortcuts.

The documentation ( says shortcodes are for pages or posts but it would be handy to be able to use this one in a text widget as well.

Can you let me know if what I am trying is possible or let me know the name of the datafeedr shortcode function and I'll try the second method in my theme.

Many thanks!

Eric September 15th, 2011 12:44 PM


It's not possible to add a shortcode to a Text widget.

The only way to deal with this is to create a widget in the Factory, configure it to display the product(s) you want and then add that widget to your sidebar in the admin area of your site.


DogWalkingGear September 16th, 2011 04:12 AM

Many thanks Eric,

I did have success by following a longer winded method and have included it here in case it is of use to anyone else. Basically I created my own shortcode and wrapped the datafeedr_tag() function.
By then using add_filter('widget_text', 'do_shortcode'); I have the shortcode functionality in my text widget.
I pass in the view name and the product number as variables.

/* Create our own shortcode to wrap a shop shortcode */
/* New shortcode is of the form [DWG_DFR view="Embedded 150 Pic Cube" productnum="491100198966992"]*/
function show_DFR_in_widget( $atts, $content = null ) {
/* Datafeedr does not yet support shortcodes in a text widget, wrap the datafeedr shortcode and display this one */
extract( shortcode_atts( array (
'view' => 'Sale Items',
'productnum' => '123456'
), $atts ) );
if ( function_exists ('datafeedr_tag') )
$DFR_result=datafeedr_tag($view.'?p='.$productnum) ;
$DFR_result='Datafeedr not configured';

return $DFR_result;
add_shortcode( 'DWG_DFR', 'show_DFR_in_widget' );

/*Add the filter to allow shortcodes to work in widget text areas */
add_filter('widget_text', 'do_shortcode');



Eric September 16th, 2011 08:05 AM

That reminds me that you could use a plugin that allows you to embed PHP in the text widget. Then I think you would be able to use the datafeedr_tag() function found here:

All times are GMT -5. The time now is 01:14 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.