Home How to How To Enable Shortcode Support In Widgets

How To Enable Shortcode Support In Widgets

358
0

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.

  1. To test this, first copy a YouTube video URL to your clipboard.
  2. Then go to Appearance, Customize, and Widgets.
  3. Choose a Widget Area such as Sidebar, and click on the Add a Widget button.
  4. Scroll down and find the Text Widget and give it a click.
  5. 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.
  6. 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.
  7. 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.

  1. To get started, in your WordPress Dashboard, go to Plugins, then Add New.
  2. Do a search for Pluginception, then click Install, and then Activate.
  3. Now, under the Plugins menu is a new link called Create a New Plugin. Click that link.
  4. Give it a name such as Add Shortcode Support for Widgets, and then click the Create a Blank Plugin button.
  5. Now copy in the code seen on the screen into to file of the plugin you created now with pluginception.
  6. Click the Update File button.
  7. 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:

add_filter(‘widget_text’,’do_shortcode’);

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.

shortcode widget wordpress

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!!

 

 

Related Post

Comments

comments