Jump to content


Photo

Shortcodes WordPress not working in widgets


  • Please log in to reply
5 replies to this topic

#1 hansonexperience

hansonexperience

    Advocate

  • Members

  • 371 posts
  • Framework Version:DMS
  • Country: Country Flag

Posted 19 March 2011 - 10:46 AM

Hi,

I tried to use shortcode from youtube as mentioned here:
 http://codex.wordpress.org/Embeds

If I use a youtube url, for example:

 http://www.youtube.com/watch?v=6qMTQrdwWmQ

it works great in postings, showing the embed without having to use the embed code of youtube.
But when I do the same in a widget in the sidebar (in a text box) it shows the url but does not use/pick up the embed code.
Perhaps this is the same problem why tubepress, smartyoutube shortcodes do not work in boxes.

#2 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 19 March 2011 - 02:09 PM

This is because by default WordPress does not allow shortcodes in text widgets! `add_filter('widget_text', 'do_shortcode')` will make it work.

#3 hansonexperience

hansonexperience

    Advocate

  • Members

  • 371 posts
  • Framework Version:DMS
  • Country: Country Flag

Posted 19 March 2011 - 08:20 PM

Hi Simon, thanks! Where do I have to enter this line? In what widget are shortcodes allowed? And why do some not work in features/boxes?

#4 hansonexperience

hansonexperience

    Advocate

  • Members

  • 371 posts
  • Framework Version:DMS
  • Country: Country Flag

Posted 19 March 2011 - 08:34 PM

Simon, I have this line as you mention put in functions.php
Does not work
 <?php
	
	// Theme Initialization -- Copyright PageLines 2010 -- Designed by Andrew Powers --
	
	// GET CORE ///////////
	
		if(file_exists(TEMPLATEPATH.'/_core/init_core.php')){
			define('CORE', TEMPLATEPATH . "/_core");
			define('CORENAME', "_core");
		}else{
			define('CORE', TEMPLATEPATH . "/core");
			define('CORENAME', "core");
		}
		include(CORE . "/init_core.php");
	
	add_filter( 'wp_feed_cache_transient_lifetime', create_function('$a', 'return 1800;') );
	add_filter( 'widget_text', 'do_shortcode');
	?>


#5 hansonexperience

hansonexperience

    Advocate

  • Members

  • 371 posts
  • Framework Version:DMS
  • Country: Country Flag

Posted 19 March 2011 - 08:48 PM

Hi Simon,

I found this:
 //Enable AutoEmbeds from Plain Text URLs in Text Widgets
	add_filter( 'widget_text', array( $wp_embed, 'run_shortcode' ), 8 );
	add_filter( 'widget_text', array( $wp_embed, 'autoembed'), 8 );
And put that in functions.php and it worked.
Thx to:
 http://daisyolsen.com/2010/10/auto-embed-media-in-wordpress-text-widgets/


#6 hansonexperience

hansonexperience

    Advocate

  • Members

  • 371 posts
  • Framework Version:DMS
  • Country: Country Flag

Posted 19 March 2011 - 09:20 PM

And after that I found out that if you want other dimension of the video, this works for a sidebar: [embed width="280" height="200"] [/embed]