A quick how-to! Today I found that using WordPress shortcodes in text widgets right out of the box didn’t work or render. I was using a custom theme I had made myself, so other themes may already have this feature. In the event your shortcodes are not working in a text widget, simply add this line to your functions.php file of your theme. Make sure that it’s within [php]<?php[/php] and [php]?>[/php] tags.
[php]add_filter(‘widget_text’, ‘do_shortcode’);[/php]
Additionally, if you’d like to render a shortcode in a theme file, use the do_shortcode function. Generall, this is not recommended because it’s not editable by the end user easily.
[php]echo do_shortcode(‘[shortcode_name]’);[/php]
Leave a Reply