How to Enable Shortcodes in WordPress Widgets

In this very short tutorial I’m going to share a little snippet to enable shortcodes in WordPress widgets. By default, all shortcodes can only be used in post and page post types.

To add shortcode support in widgets, simply paste the following code in functions.php file of your child theme:

1 2 3 4
<?php
// Add shortcode support to widgets
add_filter('widget_text', 'do_shortcode');
view raw functions.php hosted with ❤ by GitHub

Here’s the result after you’ve added the code:

enable widgets

In this example, I’m using ET Shortcodes plugin by Elegent Themes. Simply adding this shortcode to your text widget will not get the same result.

Want something more? Stephanie Leary has a very comprehensive article on enabling the shortcode on everywhere else.

Comments

  1. Areesha Noor says

    Hi admin,

    It’s so easy method,
    I never heard about this type of tutorial. it is very simple tricks.
    thanks admin for sharing with us.

    Areesha Noor!

Leave a Reply

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