313: 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: 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.

Thoughts on “313: How can I use shortcodes within a WordPress Text widget?

  • 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

    • 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.

  • 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

    • 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.

  • 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!

    • 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.

      Regards,
      Arnel C.

    • 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

  • function hs_shortcode()

    {

    ob_start();

    hs_booking_calender();

    return ob_get_clean();

    }

     

    add_shortcode(‘hs_calender_shortcode’,’hs_shortcode’);

     

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

    • 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,
      John-Paul

    • 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,

      -John-Paul

  • 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 … 

    • 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

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

    [contact-form-7 id=”2358″ title=”Contact Form 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.

Leave a Reply