Envira Gallery Blog
Digital Photography Tips, Tutorials and Resources
Digital Photography Tips, Tutorials and Resources
Last updated on Jul 30, 2016 by Waseem Abbas Reader Disclosure
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…
There are two simple methods to make shortcodes work in your WordPress sidebar widgets: with a plugin, or using code.
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.
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.
If you like this article, then please follow us on Facebook and Twitter for more free WordPress tutorials.
Envira Gallery helps photographers create beautiful photo and video galleries in just a few clicks so that they can showcase and sell their work.