Enable Use of Shortcodes Anywhere in WordPress

Simply pasting a shortcode into any of your widget areas generally won’t work.

To enable the use of shortcodes in any text widget area, on any theme, simply add this code to your child themes functions.php file.

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

This enables short codes in excerpts:

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

This enables use of short codes in your description field for archive pages

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

This enables use of short codes in comments:

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

Now all you need to do is paste your shortcodes and they will work.


Comments

4 responses to “Enable Use of Shortcodes Anywhere in WordPress”

  1. Thanks so much for posting! Worked like a charm – and saved me a TON of time. I really appreciate your tutorial library!

    1. Brad Dalton Avatar
      Brad Dalton

      You’re welcome Angela.

  2. Maggie Wall Avatar
    Maggie Wall

    So Brad,
    If all it takes is one line of code in the child theme php area, why don’t child themes just put the line in so that way people will be able to do shortcode widgets as a default / automatic thing?

    1. Hi Maggie. Some probably do whereas some want to keep the files as small as possible.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.