How to make short codes work in a widget.

2
223 followers
Updated

If you're having issues with your short codes not working in WordPress widgets and displaying on your site as a text in brackets, like this: "[example short code]" I will help you with this quick tutorial.


Why is your short code visible on your website?

The reason for it is not because there's something wrong with the plugin, that the short code comes from, or how you input the text in your editor.
It's because WordPress is not parsing short codes in widgets by default ;)

How to solve this problem?

Go to your wp-admin dashboard, than do the following:

1.Click on "Appearance", than on "Editor".

2. Find "Theme functions" tab in the right side of your browser's window, and click on it. It will open functions.php file, that needs to be edited.

3. Press "ctrl+f" on your keyboard - it will bring up a small popup somewhere in your browser's window.
In that popup type in "widgets". This will find all text containing a word "widgets" on you site and highlight it. You can move from one part of the text to another by clicking on an arrow in the popup.

4. Use the method described in previous point to find this (or similar) text in your functions.php file:

"/***** Enable Shortcodes inside Widgets *****/"

If you are able to find it, add this code right under it:

add_filter( 'widget_text', 'shortcode_unautop');
add_filter('widget_text', 'do_shortcode');

If you can't find this code, simply add it to your functions.php file, so it looks like this:

/***** Enable Shortcodes inside Widgets *****/
add_filter( 'widget_text', 'shortcode_unautop');
add_filter('widget_text', 'do_shortcode');

Make sure that the code goes before the last php tag in the file (this is the tag: ?>) and that there is no blank space after the closing php tag.
Save the file, clear cache in your browser and reload the page where you have the widget causing you trouble. Check if it worked ;)
Enjoy the rest of your day ;)



Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training

Recent Comments

2

Where abouts in the functions.php tab does the

/***** Enable Shortcodes inside Widgets *****/
add_filter('widget_text', 'do_shortcode');

need adding mate? I just pasted it to the bottom of the functions.php tab and it didn't work.

Amended the code. This should sort it out for you. You can add it anywhere in the file.

/***** Enable Shortcodes inside Widgets *****/
add_filter( 'widget_text', 'shortcode_unautop');
​​add_filter('widget_text', 'do_shortcode');

The reason it didn't work is probably because your short code is on its own line, and it would normally get wrapped in a paragraph tag. The first line "add_filter( 'widget_text', 'shortcode_unautop');" prevents that from happening.
Hope it helps ;)

See more comments

Login
Create Your Free Wealthy Affiliate Account Today!
icon
4-Steps to Success Class
icon
One Profit Ready Website
icon
Market Research & Analysis Tools
icon
Millionaire Mentorship
icon
Core “Business Start Up” Training