Enable Shortcodes in WordPress Text Widgets

Enable Shortcodes in WordPress Text Widgets

Have you ever wanted to use a WordPress shortcode in a text widget, or have you ever attempted to do so with undesired results? I have, and wanted to re-share a common little code snippet that allows you to use a WordPress shortcode from your theme or plugin within a text widget!

To enable shortcodes in a text widget on your website add the do_shortcode filter call to the widget_text hook within into your theme’s function.php file, as shown below:

add_filter('widget_text', 'do_shortcode');

Note: The only widget that calls the widget_text hook, is the text widget. This code snippet will not affect any other widgets in your library, only the WordPress Text widget.

Author: daharveyjr

I’m a solution architect responsible for the design, development, implementation, testing, and maintenance of e-commerce operations and applications using the Hybris and WebSphere Commerce product suites and other web technologies such as Java, J2EE/JEE, Spring, PHP, WordPress and more. Twitter | Facebook | LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *