Widgets are handy little applications that can be added to your website or blog to do important things like helping you with SEO, useful things like creating custom sidebars, or fun things like showing time zones from around the world.  If you already have a WordPress website, chances are that you’re probably a little familiar with Widgets.

Shortcodes are small WordPress codes that do a lot of work with just a tiny amount of effort.   Both widgets and shortcodes are extremely useful in getting the most out of using your blog, but trying to use shortcodes within the code for your widget can be a little tricky.  If you’re seeking a way to customize your WordPress blog or site, learning how to work with widgets and shortcodes is a great place to start.

Enabling the Use of Shortcodes in Your Widgets

Not knowing how to do it means that you will run into a problem any time you try to use them in your sidebar, text widgets, or any other other widget area.  There are two ways to get around this inconvenience.

The first is probably easiest, but allows for the least amount of customization.  There are plugins created for exactly this and you can go to Plugins > Search and search for a plugin that allows the use of plugins in sidebar or text widgets.   However, if you either can’t find what you need or want to do it yourself, you can do the following (Note, as always you should back up your blog before you start making changes to the code):



1. Log into your WordPress account and click on Appearance and select Editor.


2. In the list of Templates to the right, select functions.php or Theme Functions.


3. Add the following code to the functions.php file you just opened.


add_filter( ‘widget_text’, ‘shortcode_unautop’);
add_filter( ‘widget_text’, ‘do_shortcode’);

Add it at the very bottom below everything else so you don’t affect any of the code you already have in the file.



The top line of this keeps WordPress from including your shortcode into automatic paragraph tags and the second line actually allows you to use shortcode.  Use both.


If you want to allow shortcode in your comments, also add:

add_filter( ‘comment_text’, ‘shortcode_unautop’);
add_filter( ‘comment_text’, ‘do_shortcode’);


If you want to use shortcode in your excerpts, add this code:

add_filter( ‘the_excerpt’, ‘shortcode_unautop’);
add_filter( ‘the_excerpt’, ‘do_shortcode’);


Now that you’ve enabled shortcodes on your blog, you should be able to use them in your widgets as you would like to.



Author Bio:  Jack Peterson is an expert in all aspects of SEO. He loves reading and writing on all that he knows best. In other words, anything to do with SEO and he will churn out an article that will be loved by any expert in the field.