Why Shortcodes Doesn’t Work in WordPress Widgets?
In WordPress, shortcodes provide an easier way to add functionality in text areas like post editor when you are writing a post.
Often beginners think that because there’s a text widget in your sidebar, shortcodes will automatically work. By default, any text entered into the text widget goes through WordPress filters which doesn’t allow shortcodes to be executed.
Instead of seeing the final result, you will see the shortcode itself as plain text.
It is very easy to change that, and we will show you how to easily enable shortcodes to be executed in WordPress text widgets.
Method 1: Adding Shortcode Enabled Text Widget in WordPress
In this method, we will be using a simple WordPress plugin. This method is recommended for beginners who don’t want to add code manually.
First thing you need to do is install and activate the Shortcode Widget plugin.
Upon activation, you need to visit Appearance » Widgets page. There you will find a shortcode widget in the list of available widgets.
Simply add the shortcode widget to a sidebar and then add your shortcode in the content box. Don’t forget to click on the save button to store your widget settings.
This shortcode widget is just like the default text widget in WordPress. The only difference is that you can add shortcodes inside it.
Method 2: Enabling Shortcodes in WordPress Text Widget
If you are comfortable adding code to your theme, then you can enable shortcodes to work in text widgets.
Simply add this code to your theme’s functions.php file or a site-specific plugin.
This code simply adds a new filter allowing shortcodes to run inside text widget.
You can now visit Appearance » Widgets page and add a text widget to a sidebar. Paste the shortcode in the content box and click on the save button.
Visit your website to see shortcode working inside text widgets.
We hope this article helped you learn how to use shortcodes in your WordPress sidebar widgets. You may also want to see our list of 7 essential tips for using shortcodes in WordPress.