How to enable shortcodes for widgets in wordpress

This recently became a requirement of some simple work that I did creating a plugin that allowed a single piece of content to be added in wordpress then output using a shortcode. I added the shortcode to the text widget but it was simply output as a the shortcode itself. After some googling and hunting through forums I discovered the solution:

 add_filter('widget_text', 'do_myplugin_content_shortcode');

Or when in an object context use:

 add_filter('widget_text', array($this,'do_myplugin_content_shortcode'));

where the ‘do_myplugin_content_shortcode’ is the function that outputs the shortcode content.

Leave a Reply