Datafeedr Support Forums  

Go Back   Datafeedr Support Forums > Current Version (V3) Forum > Questions
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Important - The support forums are now in "read-only" mode as we transition to an alternative help desk solution. Feel free to contact us here with any of your questions or search the forums for an existing solution.
 
 
Thread Tools Search this Thread Display Modes
  #1  
Old September 15th, 2011, 12:36 PM
DogWalkingGear DogWalkingGear is offline
 
Join Date: Aug 2011
Posts: 15
Default 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
eg
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 (http://www.datafeedr.com/docs/item/185) 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!
  #2  
Old September 15th, 2011, 12:44 PM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

Hi

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.

Eric
  #3  
Old September 16th, 2011, 04:12 AM
DogWalkingGear DogWalkingGear is offline
 
Join Date: Aug 2011
Posts: 15
Default

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) ;
else
$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');

Cheers,

Brian
  #4  
Old September 16th, 2011, 08:05 AM
Eric's Avatar
Eric Eric is offline
Datafeedr Team
 
Join Date: Feb 2008
Posts: 16,902
Default

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: http://www.datafeedr.com/docs/item/185
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the text in tab youngy Questions 1 July 13th, 2011 09:11 AM
Sub Cat text not centred macfink Questions 6 March 31st, 2011 02:20 PM
Text Removal macfink Questions 1 March 29th, 2011 11:27 AM


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


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