Digital Photography Tips, Tutorials and Resources
Do you want to add shortcodes in your WordPress widgets? Sometimes you may want the convenience of using shortcodes to add new functionality to your sidebar. In this article, we will share how to make shortcodes work in your WordPress sidebar widgets.
Shortcodes are a simple method to add any functionality in WordPress: all you have to do is add a very short line of code, and you can create pretty much anything. Shortcodes work easily with the text editor in WordPress posts or pages. However, by default, WordPress sidebar widgets don’t support shortcodes.
One would think that shortcodes should work with the text widgets in sidebar. However, any text that you add in a text widget passes through WordPress filters that don’t allow shortcodes to work.
If you try to enter a shortcode into a text widget, you’ll end up with something like this:
However, you can enable shortcodes for the text widget in WordPress. Here’s how…
Making Shortcodes Work in Your WordPress Sidebar
There are two simple methods to make shortcodes work in your WordPress sidebar widgets: with a plugin, or using code.
Method 1: Using a Plugin
First thing you need to do is go to Plugins » Add New and type Shortcode Widget in the search bar. Press the Enter key.
You should click on the Install Now button to activate the Shortcode Widget plugin.
On the next page, you can simply click on the Activate Plugin link to activate this plugin.
Upon activating the plugin, go ahead to Appearance » Widgets and from the available widgets, select and drag the Shortcode Widget to the sidebar widget area.
You can add your shortcode in the text editor of this widget and hit the Save button. It will add the functionality of the shortcode in the sidebar widget in WordPress.
Method 2: Using the Code
With the code method, you can edit your theme’s function.php file and simply add this code:
// Enable shortcodes in text widgets add_filter('widget_text','do_shortcode');
It will create a new filter that surpasses the shortcodes in the text widget in WordPress, so they’ll work.
Simply go to Appearance » Widgets and add a text widget in the sidebar widget area. Then add your shortcode in the text widget and press the Save button.
Now your shortcodes will work in WordPress sidebar widgets.
We hope this article has helped you to learn how to make shortcodes work in your WordPress sidebar widgets. You may also want to check out our guide on how to create an image widget in WordPress.