How can I use shortcodes within 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 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.

0 thoughts on “How can I use shortcodes within a WordPress Text widget?

  1. hey!i’m using genesis framework with ‘genesis sample develop’ child theme. The problem i am getting is that, this theme is not rendering any shortcodes and html in text widget even after i includingadd_filter( ‘widget_text’, ‘shortcode_unautop’); add_filter( ‘widget_text’, ‘do_shortcode’, 11);to my child theme’s ‘function.php’ file. Please help me out……Thanku

    1. You’ll want to make sure you are adding the code to the functions file created for the child theme instead of the parent theme. Otherwise, I would suggest contacting Genesis to see if they have a suggestion.

  2. Hey Guys,

    I’ve changed my functions.php file to allow me to post shortcode to a text widget. My only problem now is that every text widget is showing this shortcode on my page. I’m specifically refering to using a table shortcode.


    Please help I’m new to all of this

    1. I was not able to replicate that behavior using the WordPress twenty ten theme. It’s possible there could be a theme or plugin conflict in your installation.

  3. Thanks for your work!
    In my theme I have an area in the top bar where I can add text only in the customization. Is it possible to insert a shortcode there? 

    I use MaxStore in WordPress with Woocommerce.

    Thank you!

    1. Hello Apfelsinchen,

      Thanks for the question about the shortcodes in your theme. Typically, shortcodes are only usable in the posts/pages section of WordPress. If you need more information on the customization options for your theme you will need to consult with the theme developer.

      If you have any further questions or comments, please let us know.

      Arnel C.

    1. Hello Ricky,

      What happens when you add the code to your functions.php file? You may need to contact theme forest to see if they have another method for their themes.

      Best Regards,
      TJ Edens

  4. function hs_shortcode()




    return ob_get_clean();





    hi this is my shortcode function now i have to display shortcode after the plugin content

    1. Hello dileep,

      Thank you for contacting us. We are happy to help, but I am not sure what you are asking.

      Please provide more information, so we can better assist you.

      Thank you,

    1. Hello Boris,

      Thank you for your question. I found a similar question in the Official WordPress forums, where they present several ways to enable shortcodes in excerpts.

      If you have any further questions, feel free to post them below.
      Thank you,


  5. i used LPN theme for wordpress … and the latest version of wordpress .. and the shortcode is [indeedsearchform] … anyways i found solution .. the shortcode works on pages, so i make a page and run this shortcode on that page and than parse it to the index page … 

    1. Hello Husnain,

      Sorry to hear you tried it and it did not work. What theme are you using? What version of WordPress are you using? Which shortcode did you test with to see if it worked?

      Kindest Regards,
      Scott M

  6. How can I enable contact form shortcode in HTML area( Where only allow html tag ) .

    [contact-form-7 id=”2358″ title=”Contact Form 1″]

    1. If it’s an HTML-only area, shortcodes cannot be added. You would need to use a normal location or create the form using HTML instead.

Was this article helpful? Let us know!