One of the most asked questions we get about widgets is how can we enable shortcode support in widgets in WordPress sidebar widgets? By default, shortcodes does not work in sidebar widgets. In this article, we will show you how to easily use shortcodes in your WordPress sidebar widgets.
Steps To Test & Enable Shortcode Support in Widgets
It’s possible that the steps for adding shortcode support for Widgets aren’t necessary for your web site because of your currently activated theme, or any of the activated plugins, may have added shortcode support for Widgets already.
- To test this, first copy a YouTube video URL to your clipboard.
- Then go to Appearance, Customize, and Widgets.
- Choose a Widget Area such as Sidebar, and click on the Add a Widget button.
- Scroll down and find the Text Widget and give it a click.
- In the Content area of the widget type an open square bracket, then the word youtube, then a space, then paste the YouTube URL, then type in a closing square bracket.
- In the Live Preview screen, if you see the video, then you are in luck. Otherwise, you will see just your shortcode text. If that’s the case, that means that shortcodes are currently not enabled for Widgets on your web site. Let’s correct that now by creating a small plugin.
- First, you can save your changes, or else copy your shortcode, so you can quickly paste it back in later after enabling shortcode support for Widgets.
Code used in the above steps:
Plugin Method for Adding Shortcode Support in Widgets
I find that it’s very easy and straightforward to use the Pluginception plugin to create a small plugin for purposes such as this.
- To get started, in your WordPress Dashboard, go to Plugins, then Add New.
- Do a search for Pluginception, then click Install, and then Activate.
- Now, under the Plugins menu is a new link called Create a New Plugin. Click that link.
- Give it a name such as Add Shortcode Support for Widgets, and then click the Create a Blank Plugin button.
- Now copy in the code seen on the screen into to file of the plugin you created now with pluginception.
- Click the Update File button.
- Now, go back and see if the video is now rendering, by going to Appearance, Customize, and Widgets. Paste in your shortcode into a Text Widget if it isn’t already there.
Code used in the above steps:
Adding Shortcode Enabled Text Widget in WordPress via Plugin
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 of all 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.
Finally 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. Hence the only difference is that you can add shortcodes inside it.
What am I missing here? Let me know in the comments and I’ll add it in!
The upcoming blog will be on “How to embed YouTube videos into Widgets” Stay Tuned!!