WordPress: How to use shortcodes in WordPress sidebar widgets

Shortcodes make it easy to blog and add various elements in WordPress. When using the shortcode, say, my_shortcode, you just need to add [my_shortcode] (with brackets) in the content at the desired location. However, just adding the shortcode in sidebar widgets does not execute it and you get to see the text of the shortcode. How to add a shortcode in WordPress sidebar widgets?

With a small code, you can instruct WordPress to execute shortcodes in sidebars as well. Open your theme’s functions.php file and paste the following code.

add_filter('widget_text', 'do_shortcode');

Once you add the above code snippet to functions.php, you can add shortcodes in WordPress sidebar like posts. Go to your Appearance → Widgets screen and create a text widget. Paste any shortcode that you have enabled in the sidebar widget, and it will function properly.

Premium WordPress Themes

Reliable Web Hosting

Smart Web Worker strongly recommends HostGator for your website/blog hosting. Sign up for web hosting at just $3.96/month. Use the coupon code "SMARTBLOGGER25" to get 25% discount on any hosting packages. Get an account with HostGator now!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>