Add shortcodes to WordPress Text widgets

This post is more than 11 years old.

WordPress comes with a few standard widgets, one of which is the Text widget. It’s a fairly versatile widget that lets you add simple text or even HTML into any widget zone on your website. One thing it doesn’t let you add is shortcodes. But it’s very easy to allow the Text widget to accommodate shortcodes too.

Once again, it’s hooks to the rescue. The Text widget has a few filter hooks that let you modify its behaviour, and we’ll use one of them to let it process shortcodes. And all it takes is one line of code, which you can drop into your theme’s functions.php or a simple plugin file.

add_filter('widget_text', 'do_shortcode');