• Skip to primary navigation
  • Skip to main content
  • Skip to footer
Alex Mustin
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
Alex Mustin
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
Alex Mustin

Alex Mustin

  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me
  • About
  • Services
  • WordPress Tips
  • Websites
  • Plugins
  • Contact Me

How To Enable Shortcodes in Widgets, Comments and Excerpts

March 14, 2015 in Code Snippets, Development

In WordPress, you can use shortcodes in the content of your pages and posts. Unfortunately, when you attempt to use shortcodes in Widgets, it won’t work properly — the WordPress default behavior is to output the text of the shortcode, instead of processing it:

[my-shortcode]

There is a way to enable shortcodes in widgets, comments, and excerpts in WordPress, by using the “do_shortcode” function. Add the following code to your functions.php file:

// ENABLE SHORTCODES IN WIDGETS //
add_filter('widget_text', 'do_shortcode');

// SHORTCODES IN COMMENTS //
add_filter( 'comment_text', 'do_shortcode' );

// SHORTCODES IN EXCERPTS //
add_filter( 'the_excerpt', 'do_shortcode');

Now, when you go to use the shortcode, it will be processed on the page as expected.

Filed Under: Code Snippets, Development

Reader Interactions

Leave a Reply Cancel reply

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

Footer

Developing creative WordPress websites and solutions for companies of all sizes since 2008.

SOLUTIONS

  • One-Page Website
  • Maintenance Service

RESOURCES

  • Client Login
  • WordPress Tips
  • Mastodon

© 2023 Alex Mustin