Ever have this really cool shortcode that you wanted to use in your sidebar? You paste it in the text widget and save your changes but when you view your page you just end up with the shortcode itself?
The reason for this is simple. The WordPress text widget doesn’t parse shortcodes by default. So when you place your shortcode in the widget it just sees it as basic text. But there is a super easy way to remedy that. Just add the code below to a functionality plugin.
[php]
add_filter( ‘widget_text’, ‘shortcode_unautop’);
add_filter(‘widget_text’, ‘do_shortcode’);
[/php]
The first line is only needed if you plan on having other text or elements and checking the “add paragraphs automatically” box. Otherwise WordPress might wrap your shortcode in paragraph tags and you don’t necessarily want that.
That’s all there is to it and I hope you enjoy.
Leave a Reply