How to Use Shortcodes in a WordPress Text Widget

By default, WordPress shortcodes do not work within Text widgets. If you need this functionality, it is quite easy to accomplish, simply follow the steps below.

Using Shortcodes in a WordPress Text Widget

  1. Log into your WordPress Dashboard
  2. Under “Appearance” click “Editor”
  3. In the list of files on the right of the page, click “functions.php”
  4. At the bottom of the functions.php file, add the following code:
    add_filter( ‘widget_text’, ‘shortcode_unautop’);
    add_filter( ‘widget_text’, ‘do_shortcode’);

    editing your themes functions.php file

  5. Click “Update File” and your shortcodes should now work in your Text widgets!
Before: After:
before shortcodes could be used in text widgit
after shortcodes can be used in a wordpress text widgit

Changes made to these files may get overwritten after theme updates. It is always recommended to make these kinds of modifications in a child theme.

Looking for more guides? We have over 400 WordPress How To Articles to help you!

Share this Article