Make WordPress Shortcodes working in Widgets

Make WordPress Shortcodes working in Widgets

WordPress Shortcodes allow users to add an inbuilt or plugin-driven functionality into their posts and pages without using PHP or any sort of coding. Take the gallery shortcode [gallery] as an example, it enables the user to add an existing WordPress gallery into their posts or pages. Different WordPress plugins provide shortcodes to add functionality in posts and pages at user’s convenience.

However, if you try to put a shortcode in your sidebar widgets, it won’t work, since WordPress don’t allow to add shorcodes in widgets by default. But we do have a hack to get over it.

To make shortcodes working in your widgets, just add the following line of code in the end of your theme’s functions.php, just before the closing PHP tag, i.e. ?>:

add_filter('widget_text', 'do_shortcode');

Now, save the changes and try adding a shortcode in your sidebar widgets. You’ll see it working. I hope you found it useful.