How to Use Shortcodes in WordPress Sidebar Widgets

Are you looking for how to Use Shortcodes in WordPress Sidebar Widgets? Find the best methods by WP experts.

In the past, we have shown how to add widgets in WordPress. A sidebar is also an important widget used in WordPress. We think to paste shortcode in sidebar widgets instead of writing HTML because it became little confusing when you write HTML in widgets. So to overcome this issue we use Shortcodes. We think there is a Text widget that we can use in a sidebar widget to place shortcode. But Widgets goes through filters so it does not allow to execute shortcode. Instead of seeing the final result, you will see the shortcode itself as plain text. So here we will discuss how we can use the shortcode in the sidebar widgets.
 

What is Shortcode?

A shortcode is a WordPress-specific code that lets you embed files with using a single line. It is easier to create a file or object somewhere and using that file at multiple places by using just a single line. So you don’t need to write HTML every time and it will also save lots of time. Generally, it is enclosed in square brackets [ ]. So it is easier to manage content using shortcodes.
 

Method: 1 Adding shortcode in widget using plugin

In this step, we use a plugin so that it is easier to use for beginners who don’t want to use code manually.

     

  • Log in to the dashboard and hover on Plugins tab given in the left sidebar and then click on Add New option.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Search Shortcode Widget in the Search Plugins field given on the right side of the page.
     
    How to Use Shortcodes in WordPress Sidebar
     

  •  

  • Install and activate the plugin. If you don’t know how to install and activate plugin read our previous article. See below image of the Plugin:
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Hover on Appearance tab given in left panel and click on Widgets option.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Here you can find Shortcode Widget in the list of available widgets.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Simply add the widget to your sidebar and then add your shortcode in the content box. You can use any shortcode here. For example, we are using a Slider shortcode here.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Then click on Save button given below of widget to save your changes.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Visit your website to see the changes.

How to Use Shortcodes in WordPress Sidebar Widgets method two

Method: 2 Enable Shortcode in widget using Code

If you can use code or you have knowledge of how to use a code in theme files then you can enable shortcodes to work in the text widget.

     

  • Locate your function.php file inside the theme and open in an editor and paste the below code:
     

    // Enable shortcodes in text widgets
    add_filter('widget_text','do_shortcode');

     
  • Now again hover over Appearance option given in left panel and click on Widgets option.
     
    How to Use Shortcodes in WordPress Sidebar
     

  •  

  • Take a Text widget from the list of available widgets and add it to your sidebar. Then add the shortcode in the content box.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Then click on Save button given below of widget to save your changes.
     
    How to Use Shortcodes in WordPress Sidebar
     
  • Visit your website to see the changes.

We hope this article will help you learn how to use a shortcode in sidebar widgets.
 
You can also check how to add widgets in the footer. To know how to add widgets in the WordPress theme footer read our previous article.

Spread the love

Kapil Garg

Kapil Garg has 7 years of experience in building professional websites. He is a leading web developer, web designer and Google adwords certified partner. His passion is to designed and developed most impressive websites.

One thought on “How to Use Shortcodes in WordPress Sidebar Widgets

  • October 31, 2017 at 2:17 pm
    Permalink

    Very nice site,keep on posting.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *