Jump to content
Sign in to follow this  
hansonexperience

Shortcodes WordPress not working in widgets

Recommended Posts

hansonexperience

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.

Share this post


Link to post
Share on other sites
Simon

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

Share this post


Link to post
Share on other sites
hansonexperience

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?

Share this post


Link to post
Share on other sites
hansonexperience

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');
	?>

Share this post


Link to post
Share on other sites
hansonexperience

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/

Share this post


Link to post
Share on other sites
hansonexperience

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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×