How To Enable Shortcodes in Widgets, Comments and Excerpts
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.
Leave a Reply