Post Pic

How to: Add shortcodes in sidebar Widgets

You know it, I love shortcodes, and wrote about time some days ago. But a very frustrating thing is that you can’t add shortcode in sidebar Widgets. You can’t? yes, unless you read that recipe!

To allow shortcodes in sidebar widgets, simply edit the functions.php file from your them and add the following code:

add_filter('widget_text', 'do_shortcode');

Once you saved the file, you can now add as many shortcodes as you want in sidebar widgets.

Credits goes to English Mike for this awesome recipe!

12 Responses

Feb 22 2012 07:36

Works for the most part, although with a shortcode that generates CSS dynamically, it neglects to generate the necessary CSS.

Feb 29 2012 01:56

It’s funny because I was able to add shortcodes to my wordpress (3.3.1) no problem. Then I did a search and found this post, did exactly as instruction and now it works….My question is, why would it stop working after it worked for so long?

weird….

Thanks though!

Apr 17 2012 14:23

Excellent – thanks for this. Used it to get Soundcloud working in a sidebar widget.

May 24 2012 23:55

Thank you! (:

Jun 17 2012 21:41

Thanks it worked!

Jul 12 2012 10:33

Thanks Dude. :)

Jul 18 2012 22:06

Superb. I really want this Functionality (Shortcode) in Widget.
Thanks.

Sep 03 2012 17:21

I tried this and it put the shortcode for my contact form in the sidebar, but the shortcode then the contact form ceased working when I used the shortcode in the widget sidebar. The form works OK on the page, but not when I make the above change & then put my contact form in the widget sidebar, using its shortcode.

Just wondering if anyone else has had problems with shortcodes/plugins ceasing to work properly when they employ the above tactic to put the same shortcode in the widget sidebar?

Sep 11 2012 11:00

I cannot for the life of me get this to work!?

Adding this into functions file

Causes my whole sidebar to not display at all? I’m using the Bones Theme on WordPress 3.3.2

Anyone had similar issues?

Oct 20 2012 22:09

Working fine, Thanks a lot…..

Dec 10 2012 18:36

Your solution is brilliant!!! Just added testimonial submission form to sidebar on testimonials page for client project! thanks for the simple and easy solution!!

All the best-
Markus

Jan 14 2013 00:38

Didn’t work for me, but not sure I placed the code in the right place. Here is where I placed it in my functions.php file from my theme.

/**

* Register widgets.

*/

function ifp_widgets_init() {

register_sidebar(array(

‘name’ => ‘Full Sidebar’,

‘id’ => ‘sidebar-widgets’,

‘description’ => ‘These are widgets for the sidebar.’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”

));

register_sidebar(array(

‘name’ => ‘Left Half Sidebar’,

‘id’ => ‘sidebar-left’,

‘description’ => ‘These are widgets for the left sidebar.’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”

));

register_sidebar(array(

‘name’ => ‘Right Half Sidebar’,

‘id’ => ‘sidebar-right’,

‘description’ => ‘These are widgets for the right sidebar.’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”

));

register_sidebar(array(

‘name’ => ‘Box 1′,

‘id’ => ‘box-1′,

‘description’ => ‘This is the first widget of the four-box section’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”,

));

register_sidebar(array(

‘name’ => ‘Box 2′,

‘id’ => ‘box-2′,

‘description’ => ‘This is the second widget of the four-box section’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”,

));

register_sidebar(array(

‘name’ => ‘Box 3′,

‘id’ => ‘box-3′,

‘description’ => ‘This is the third widget of the four-box section’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”,

));

register_sidebar(array(

‘name’ => ‘Box 4′,

‘id’ => ‘box-4′,

‘description’ => ‘This is the fourth widget of the four-box section’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”,

));

register_sidebar(array(

‘name’ => ‘Footer’,

‘id’ => ‘footer-widgets’,

‘description’ => ‘These are the footer widgets’,

‘before_widget’ => ”,

‘after_widget’ => ”,

‘before_title’ => ”,

‘after_title’ => ”,

));

}

add_action (‘widgets_init’, ‘ifp_widgets_init’);
add_filter(‘widget_text’, ‘do_shortcode’);

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox