Shortcodes in Text Widgets

When you need to add a shortcode to a Text Widget, you may find that this appears literally rather than showing the shortcode content.

Fortunately you can do this easily by adding the do_shortcode function to the widgets by using a filter that you can hook into to do this.

Enabling shortcodes in widgets is as simple as adding this code to your functions file, or to your site specific plugin (making sure that you add an opening PHP tag if necessary) to enable shortcodes in the main content of a Text Widget:

add_filter( 'widget_text', 'do_shortcode' );

You can also add shortcodes to the title of a Text Widget but using the title filter:

add_filter( 'widget_title', 'do_shortcode' );