• Skip to primary navigation
  • Skip to main content
  • Skip to footer
  • Books
    • Content Strategy for WordPress (2015)
    • WordPress for Web Developers (2013)
    • Beginning WordPress 3 (2010)
  • Blog
    • Content Modeling for WordPress
    • WordPress Hidden Gems
    • Web Design
  • Work
    • MLIS Class Projects (2019-2022)
    • Portfolio (2002-2019)
    • Services
    • WordPress Plugins
    • WordPress Themes
    • Presentations and Interviews
    • on GitHub →

Stephanie Leary

Writer, WordPress consultant, recent MLIS grad

  • About
    • Press Kit
    • Presentations and Interviews
  • Contact Me

using shortcodes everywhere

February 13, 2010 Stephanie Leary 104 Comments

Read this in Spanish | Leer esta en Español
Read this in Turkish | Türkçe bunu okuyun

At the moment, shortcodes in WordPress are processed only in post/page content. You can use them in lots of other places, though, if you enable them for each field you want. Here’s how to use shortcodes in widgets, excerpts, comments, theme files, user descriptions, and category/tag/taxonomy descriptions.

Text Widgets

It’s easy to make shortcodes work in text widgets. Just add the following to your functions.php file:

add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');

The second line is the one that makes the shortcodes work, but you’ll want to include both. If you check “add paragraphs automatically” on the widget, WordPress will apply the autop filter — the one that turns your line breaks into paragraph and break tags. If a shortcode is on its own line, it would normally get wrapped in a paragraph tag. The first line prevents that from happening.

Template Files

You can use shortcodes right in your theme! Use the do_shortcode() function, where the argument is a string that contains a shortcode.

For example, to print the output of the shortcode [foo] in a theme, add this to the file:

<?php do_shortcode('[foo]'); ?>

The do_shortcode() function accepts any text as its input. If the string contains a shortcode, that code will get processed. So, for example, you could manually process your post content for shortcodes like this:

<?php $content = get_the_content();
echo do_shortcode($content);
?>

Comments

Do you trust your commenters enough to allow them to use shortcodes? This goes into functions.php:

add_filter( 'comment_text', 'shortcode_unautop');
add_filter( 'comment_text', 'do_shortcode' );

Excerpts

To enable shortcodes in excerpts, add these lines to your functions.php file:

add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');

User Descriptions

There is no filter (as far as I know) for the user description, so in order to display the description with shortcodes, you’ll need to fetch the description string, then pass it to the do_shortcode() function. This would go into your theme file:

<php // $user_id = 3;
$userdata = get_userdata($user_id);
echo do_shortcode($userdata->description);
?>

Category, Tag, and Taxonomy Descriptions

These descriptions can be filtered, so the code for your functions.php file is simple:

add_filter( 'term_description', 'shortcode_unautop');
add_filter( 'term_description', 'do_shortcode' );

WordPress bio, biography, categories, Content, descriptions, html, Metadata, rich text, shortcodes, tags, taxonomy, template tags

Reader Interactions

Comments

  1. norrige dalla says

    March 16, 2010 at 1:42 pm

    Does not work on 2.9.2 at least.

    Reply
  2. Stephanie says

    March 16, 2010 at 1:54 pm

    I just tested again in 2.9.2 and it’s working beautifully. Which one did not work for you?

    Reply
  3. LoneWolf says

    May 28, 2010 at 7:47 pm

    I think that the shortcode_unautop has been deprecated under 2.9.2 which could cause problems.

    Also, I thought that changing the functions.php file, while easy, can lead to problems if you change themes or get an updated version of a theme that overwrites the functions.php.

    I created a simple plugin to allow the widget shortcodes that should work with any theme. It also checks for the existence of shortcode_unautop before hooking it in.

    You could modify the plugin to add functionality for shortcodes in other areas as needed (I currently only need it for widgets) by adding the appropriate add_filter calls.

    http://blogs.wcnickerson.ca/wordpress/plugins/widgetshortcodes/ is where you can find it.

    Reply
    • steph says

      May 31, 2010 at 9:00 pm

      It hasn’t been deprecated as of today’s trunk. It was just introduced in 2.9.0, so I think it’ll be around a while.

      Reply
      • LoneWolf says

        May 31, 2010 at 9:17 pm

        Ah! That explains it. I haven’t upgraded the version on my PC for a while and it is older than 2.9.0. Probably a good thing since it forced me to add the check for existence. Now it will work okay on older setups as well as the newer ones.

        Thanks Stephanie.

        Reply
  4. Russell says

    June 6, 2010 at 1:02 pm

    I’m a an amateur at all of this, so please be gentle (and simplistic) with me, thanks.

    RE: shortcode in excerpts

    Wasn’t sure which functions.php file to use (WP or theme), and no idea where to place the code, so I experimented with both. Placing it in the theme functions.php file did nothing (shortcode still showing up in excerpts as text), and when I put it in the WP functions.php file, my entire site disappeared.

    Thanks for any help!

    Reply
  5. Frank C says

    July 2, 2010 at 3:44 pm

    You can’t just cut-and-past the code in the article above into your WordPress functions.php file because WordPress has made the single quotes into ‘smart quotes’. This means that the quotes won’t be recognized as valid PHP code until you change them back to regular quotes. Once you do that, it should work OK.

    Also, when pasting it into your functions.php file, make sure that you paste it into a PHP area, not an HTML area, and in an area where it won’t conflict with other code that might be there.

    Reply
    • steph says

      July 5, 2010 at 2:06 pm

      Thanks for letting me know about the quotes. They got mangled in the database at some point since I posted this; I’ve fixed them all.

      Most functions.php files don’t have much HTML, but you’re right, all these code snippets should go in the PHP sections.

      Reply
  6. Nick says

    July 27, 2010 at 8:48 pm

    This is a fantastic post. I’m sure it’s been very helpful for many people. I know it was for me.

    I do wonder whether it is possible to use a shortcode in a page or site title, though?

    Reply
  7. Ali says

    August 20, 2010 at 5:24 am

    Wow, This is very nice post.
    I needed these codes as i am pretty new to wordpress and it will make my life easier.

    Thanks for this

    Reply
  8. Ryan says

    August 26, 2010 at 10:50 am

    Hi, I was wondering how to use shortcodes in a non wordpress site hosted on the same server. My front end is WordPress and the backend Admin panel is HTML based. My goal is to use WordPress widgets (shortcodes) on my HTML based admin panel. Is this possible?

    Reply
    • steph says

      August 28, 2010 at 4:56 pm

      Ryan, shortcodes rely on the WordPress backend, so there’s no easy way ton use them outside WP. Sorry!

      Reply
      • Ryan says

        August 29, 2010 at 6:57 am

        Steph, I found the solution: require_once(‘blog/wp-blog-header.php’); This loads the WordPress enviornment and all the shortcodes anywhere.

        Reply
  9. Ryan says

    August 26, 2010 at 11:17 am

    sorry forget to check notify!

    Reply
  10. Jan says

    August 29, 2010 at 2:10 am

    I can’t get it to work. I retyped the code into my functions.php file, I added it at the very beginning, but it’s still not working. Can anyone see anything wrong here, running wp 3.1.

    &lt;?php 
    add_filter('widget_text', 'shortcode_unautop');
    add_filter('widget_text', 'do_shortcode');
    
    require_once(TEMPLATEPATH . '/epanel/custom_functions.php'); 
    
    require_once(TEMPLATEPATH . '/includes/functions/comments.php'); 
    
    require_once(TEMPLATEPATH . '/includes/functions/sidebars.php'); 
    
    load_theme_textdomain('Professional',get_template_directory().'/lang');
    
    require_once(TEMPLATEPATH . '/epanel/options_professional.php');
    
    require_once(TEMPLATEPATH . '/epanel/core_functions.php'); 
    
    require_once(TEMPLATEPATH . '/epanel/post_thumbnails_professional.php');
    
    function register_main_menus() {
    	register_nav_menus(
    		array(
    			'primary-menu' =&gt; __( 'Primary Menu' )
    		)
    	);
    };
    if (function_exists('register_nav_menus')) add_action( 'init', 'register_main_menus' );
    
    $wp_ver = substr($GLOBALS['wp_version'],0,3);
    if ($wp_ver &gt;= 2.8) include(TEMPLATEPATH . '/includes/widgets.php'); ?&gt;
    Reply
  11. asif says

    September 15, 2010 at 2:13 pm

    Not working for me in 3.0.1

    Reply
    • steph says

      September 15, 2010 at 2:58 pm

      Which part is not working, Asif?

      Reply
  12. Jan says

    September 15, 2010 at 10:37 pm

    turns out there was a tiny bit of code I needed in my footer file.
    I needed this little bit of php before the close of my tag.
    <code

    Reply
  13. Rob says

    September 17, 2010 at 3:08 pm

    I’m running 3.0.1 and I can’t seem to get this to work. I want to show shortcode in my excerpts. I put the appropriate filters in my functions file, but it doesn’t do anything…

    Reply
  14. Jay Collier says

    September 22, 2010 at 8:59 am

    It’s interesting, Stephanie. In 3.01, adding this to my functions.php file …

    add_filter(‘widget_text’, ‘do_shortcode’);

    … is not enabling shortcodes in text widgets for me, either.

    Reply
  15. steph says

    September 22, 2010 at 4:06 pm

    I’m looking into the problem with excerpts in 3.0.1. Stay tuned!

    Reply
  16. XYDAC says

    October 13, 2010 at 3:59 am

    Thank you very much,
    It really helped :)

    Reply
  17. Stuart says

    October 21, 2010 at 3:27 am

    Thanks for this article. I’d been trying to put shortcode into a widget I’d written to allow custom sidebar text on a per post basis and was not having any luck with it.

    Google gave me a heap of posts using the add_filter method but it just wasn’t working for me.

    Thankfully one of those posts linked to yours and writing the do_shortcode directly into the widget function got it working.

    Reply
  18. Stephanie says

    November 10, 2010 at 4:46 pm

    I found out what’s happening with excerpts in 3.0+. All shortcodes are stripped from the text before the excerpt is generated. It looks like the Advanced Excerpt plugin can work around this, though, so give it a try if you need shortcodes in excerpts.

    I’m still looking into the problem with text widgets.

    Reply
  19. David Gwyer says

    November 24, 2010 at 4:32 am

    Not working in WordPress 3.01 for me either. Text widgets just outputs the shortcode tags instead of processing it.

    Reply
  20. Jen says

    November 30, 2010 at 10:13 pm

    It is nice there’s a plugin for getting around stripping of shortcodes in excerpts. However, if you’re building a theme a short and sweet method would be a better way to go. Currently, using a dropcap shortcode actually removes the entire first letter of the post along with the shortcode.

    Reply
  21. Christopher Ross says

    December 30, 2010 at 9:52 am

    Thanks for this! I’ve been struggling most of the morning with the get_the_content() and this solved my grief. Chris

    Reply
  22. Martin says

    January 19, 2011 at 12:10 pm

    Thanks! Exactly what I needed. Worked like a charm on WP 3.0.4

    Reply
  23. Montana Flynn says

    January 20, 2011 at 5:07 pm

    Thanks so much for this, I was looking for a way to put a theme shortcode in my custom widget and modifying your text widget example did just the trick!

    Reply
  24. roy says

    February 3, 2011 at 1:00 pm

    Hi,

    How can i create a short code for widget?

    i found this code
    http://digwp.com/2010/04/call-widget-with-shortcode/

    but in this line that should be inserted in the html page

    [widget widget_name=”Your_Custom_Widget”]

    what is the name of the widget?

    for example Recent posts widget

    is the name is recent posts or something else?

    Thanks!

    Reply
  25. chris says

    February 10, 2011 at 1:31 pm

    I am using WP 3.5 Latest Twenty Ten theme.
    Advanced Excerpt
    Excerpt Editor
    WP PostRatings

    I use Excerpt editor so I can display different content on the blog page/archive etc. then when someone clicks the title of the post, it brings them to the posts individual page. and displays different content (slightly different)

    THe problem is, on the blog page,/archive etc.. the short code for Wp postratings is no longer displaying the ratings for that post. its just the textual short code. i used the two lines of code above and cant seem to get it to work.
    any idea?
    Thanks

    Reply
  26. Bryan says

    March 3, 2011 at 11:13 pm

    I am also running into an issue with text widget output. It’s simply returning the shortcode as a string. I tried it also with ‘widget_execphp’ with no luck. Running 3.0.5

    Bummer.

    Reply
  27. stephanie says

    May 2, 2011 at 10:07 pm

    Hi Stephanie,

    I just ran across your post while have been searching for a way to run a shortcode within the output of another shortcode.

    I’m using the q and a faq plugin by raygun. Some of my faq answer items need to have tables for aesthetically pleasing output.

    I initially tried inserting the 2 lines of code into the php file of the q and plugin, but no result.

    Do you know if running a shortcode within the output of another shortcode is possible? If so, how would I go about getting it to work?

    Thanks for any help you can provide!
    Steph

    Reply
    • stephanie says

      May 3, 2011 at 2:18 pm

      the developer just released an update to the plugin that allows shortcodes in the output of the q and a faq plugin shortcode!

      Reply
  28. Veloz Skate Company says

    July 27, 2011 at 1:13 pm

    Oh my! SO SIMPLE! Thank you so much! I tried about 3 other plugins that didn’t work… this was a simple two line code edit!

    Thanks again!

    Reply
  29. Mitch says

    August 21, 2011 at 1:59 pm

    Hi, Using Version 3.2.1, I just pasted the shortcode into the functions.php right before the closing ?> tag and the text widget simple outputs the shortcode and not the form it’s calling.

    Here’s the code I pasted.

    add_filter( ‘widget_text’, ‘shortcode_unautop’);
    add_filter( ‘widget_text’, ‘do_shortcode’);

    Is there something new I need to know?

    Thanks!

    Reply
  30. karthimx says

    September 4, 2011 at 3:08 pm

    Working great for my wordpress blog. thanks for small code.

    Reply
  31. Adam says

    October 20, 2011 at 7:53 pm

    Thanks, but doesn’t work for me when using amazon-tools plugin in the custom excerpt box.

    The advanced excerpt plug-in does work on my site though.

    Reply
  32. John Newell says

    November 6, 2011 at 5:39 pm

    Hi – thanks for the inspiration that enabled me to find a way to add shortcodes where they can enhance my sites- specifically in sidebar widgets.

    I am not that technically minded, but sometimes a different approach (from naivety) works.

    I simply :
    >> added shortcodes to a TEXT widget
    >> added breaks between lines
    >> enabled “auto add paragraphs”

    It worked and is so much easier that coding up
    Please note it worked on ALL but ONE of my sites I have tried it on
    but 11/12 is a good result and worth trying out –
    See examples on the following pages ( not set to appear on all pages yet – as I am using Widget Logic to put widget at top of only certain pages listed below – and shortcodes help HIGHLIGHT the links to my desired outcome ) _ I am also still finishing off the site…….

    (Again- thanks for the inspiration and hope some of your readers find this useful )

    Spell Night – Ultimate Girls Night In
    Spell Night – Night of Magic
    Spell Night – Celebrate Friendship
    Hosting a Spell Night

    Reply
  33. Cris says

    November 11, 2011 at 12:50 pm

    Hi,
    Im trying to get short-codes to work on excerpts
    I tried adding this add_filter to the php file of the theme and nothing happened. I tried adding to WordPress php file, and got that add_filter is not a recognized function.
    I added the advanced excerpt and unchecked the option to remove short-codes from excerpt and still can’t get them to work.
    Any more ideas?? I have the latest version of WordPress in a multisite environment, but the advance plugin is only active on one site.
    Thanks

    Reply
  34. msrosyidi says

    December 17, 2011 at 2:29 am

    thanks so much, this code very helps me:

    add_filter( 'comment_text', 'shortcode_unautop');
    add_filter( 'comment_text', 'do_shortcode' );

    Reply
  35. Andrew Benbow says

    December 19, 2011 at 8:06 pm

    For the excerpt you need to replace

    the_excerpt()

    with

    echo do_shortcode(wpautop(wptexturize(get_the_excerpt())))

    in your theme loops

    Reply
    • Amelia says

      July 8, 2012 at 7:04 pm

      I’m having trouble getting the columns to pull up using that code for my excerpts. It’s all stacked to the left. Can you help me out?

      Reply
  36. Dan Imbrogno says

    February 8, 2012 at 11:15 pm

    I’ve found a quick way to get shortcodes working for all excerpts whether they are manually or automatically generated. Basically you have to unregister WordPress’ core filter that handles the generation of the excerpt and register your own modified version.

    You can read the detailed explanation and sample code on my blog

    Reply
  37. ray says

    February 12, 2012 at 7:57 pm

    Thanks for a great tutorial Stephanie…
    Very good info
    8-|

    Reply
  38. Judavi says

    February 26, 2012 at 8:47 am

    Omg! Thanks :)

    Reply
  39. Richard says

    March 29, 2012 at 3:04 pm

    For some reason the shortcodes in widgets isn’t working for me. I use a child theme to edit my functions.php, could that be the problem?

    Reply
  40. michael Ramirez says

    April 9, 2012 at 1:42 am

    so how can I get short codes to work in another plugin? I want to get the rokbox light box function working in the wp-download manager template area.

    Reply
  41. Rohit Manglik says

    May 27, 2012 at 1:02 pm

    Thanks a lot for the description.. It worked for me

    Reply
  42. Miracle says

    June 11, 2012 at 7:29 pm

    How to use do_shortcode or short code in option page or admin page?
    It seems not work in menu page , option page …

    Reply
    • Dustin says

      March 12, 2017 at 2:08 pm

      I’m wondering this too! Trying to use a shortcode in a desktop widget

      Reply
  43. Jeff says

    October 16, 2012 at 12:02 pm

    This is awesome. Thanks for this. I think I am so close to figuring out what is going on with me. I have a custom field I am using with shortcodes in it that I would like to run. I thought perhaps

    add_filter( ‘get_post_meta’, ‘shortcode_unautop’);
    add_filter( ‘get_post_meta’, ‘do_shortcode’);

    But no luck so far. Anyone have any ideas how I might run shortcode in a custom field. do_shortcode will not work because there is other content in the field.

    Reply
    • Stephanie Leary says

      October 16, 2012 at 4:12 pm

      Hey, Jeff. Adding a filter won’t work because the standard filters that are applied to the_title, the_content, etc. aren’t applied to custom fields. What you need to do is more like this:

      global $post;
      $content = get_post_meta( $post->ID, 'my_custom_field', true );
      echo do_shortcode( $content );
      
      Reply
      • Jeff says

        October 16, 2012 at 4:33 pm

        Awesome. Thanks Stephanie. You are awesome as always!! :)

        Reply
        • Peter says

          November 17, 2014 at 8:27 am

          Hi All,

          Which file these lines need to be put in for shortcodes to work in Custom fields?
          functions.php, loop.php?

          Any advise on this will be greatly appreciated,
          P

          Reply
  44. Melissa says

    October 18, 2012 at 10:39 am

    Stephanie: how do I contact you for consulting work? The Quote page has no form and the Support Forum link does not exist? Are you still doing custom projects? Thanks!

    Reply
    • Stephanie Leary says

      October 18, 2012 at 11:24 am

      Oh dear. I knew some things were broken, as I’m moving hosts and domains, but the contact form is rather essential! Thanks for letting me know. I’ll email you.

      Reply
  45. jack says

    November 8, 2012 at 3:27 am

    I’m not able to get this working on the footer of an older theme, I guess it only works on new themes?

    Reply
    • Stephanie Leary says

      November 8, 2012 at 2:29 pm

      How are you trying to make it work in the footer? Text filters aren’t applied to theme files, so unless there’s a widget in your footer, you’ll need to run the shortcode directly on the content in question, just like I showed Jeff above.

      Reply
  46. web development company says

    November 16, 2012 at 5:17 am

    Wow, if I had known this while doing my last WordPress project, it would have made my life so much easier. Unfortunately for deadline restrictions, I didn’t have time to thoroughly research it.

    Thanks for sharing!

    Reply
  47. Remco says

    November 22, 2012 at 4:36 am

    Super, worked! Thanks a lot))

    Reply
  48. Divye says

    December 5, 2012 at 10:31 am

    Hey Steph,

    Thanks for the quick guide.

    I am actually using private blog plugin, that allows me to set up to 10 passwords for my users.

    I won’t to add a shortcode on the welcome page (template is in html). How to make it work? Thanks in advance.

    Reply
  49. Bob says

    January 15, 2013 at 1:58 am

    Hi Stephanie, thanks for so much information. I am new to this, but I am hoping you can help me. Do you know why my shortcode is only producing the first word in a couple word meta key? I created the shortcode using array to allow for attributes in a href. It works great, yet the text of the href is only kicking back the first word in the meta_key submission. I am not sure if the array is the issue or what? Any help would be appreciated

    Reply
  50. David Radovanovic says

    January 22, 2013 at 7:29 am

    Was looking all over for allowing shortcuts in category descriptions. Thanks for sharing.

    Reply
  51. Nur Ahmad Furlong says

    February 13, 2013 at 9:05 am

    Thanks a ton for this nice little guide.

    Is this suppose dto work with custom shortcodes created through extra shortcode functions or only default WordPress shortcodes?

    I tried the sidebar widget text thing in a multisite install which has some custom shortcodes added to it. The custom shortcodes were created through a function we had developed.

    Haven’t managed to get them to execute in text widgets with this function. Anybody used this successfully on multisite with custom shortcodes?

    Reply
  52. Merk says

    February 25, 2013 at 12:25 pm

    Nice and simple! Have been looking, but others are not as well explained.
    Thanks for this great post.

    Reply
  53. Jim says

    March 7, 2013 at 2:12 pm

    Thanks! Worked great for category descriptions.

    Reply
  54. WPExplorer says

    March 26, 2013 at 2:42 pm

    Just what I was looking for – dam very comprehensive. Thanks.

    Reply
  55. Ralph says

    April 2, 2013 at 12:41 pm

    Great job! Thanks a lot!

    Reply
  56. Ilya says

    April 3, 2013 at 11:34 am

    OMG!
    Thank you!!!!!!!!!!!

    I killed a day to make it work for category_description,

    I tried
    add_filter( ‘category_description’, ‘do_shortcode’ );
    but it doesn’t work.

    Your solution
    add_filter( ‘term_description’, ‘shortcode_unautop’);
    add_filter( ‘term_description’, ‘do_shortcode’ );
    worked perfectly!!!

    thankyou-thankyou-thankyou!

    Reply
  57. Lars says

    June 13, 2013 at 4:31 am

    Old topic but still relevant… A lot of people struggle with this and do not understand why shortcodes does not work in widgets. It can also be done in code using $output = do_shortcode($output); to ensure the output is checked for shortcodes to be executed!

    Reply
  58. Anes P.A says

    September 6, 2013 at 1:18 am

    Hi Stephanie,
    It’s a fantastic post . Thanks alot .
    I need 1 more information , do we can access the shortcode logic from outside the WordPress.
    I am planning to write a REST API which provide the service for non-wp site . If the short code
    stuff can access by the outside API , it’s easy to implement it . Please advise me , I am novice in WP.

    Thanks
    Anes

    Reply
  59. RayS says

    December 4, 2013 at 2:00 pm

    Have a shortcode that works in widgets (plugin latestbyauthor) using syntax of:
    [latestbyauthor author=”authorname” show=”nn”]
    (nn defaults to 10)

    Would like to build a page with a search form whose argument would be passed as the ‘author’ keyword to create a page of links to the searched-for author’s posts.

    Done a lot of work with forms via javascript and VBscript but rather new to PHP and can’t figure out how to get the argument to the php echo command

    Reply
  60. Justin says

    January 17, 2014 at 2:56 am

    Just used your advice for a client’s Woocommerce site. Needed to display PDF parts lists in a category description. And now I can! Thank you soooo much.

    I was unable to use various PDF embed or viewer plugins because shortcode wasn’t working in the description. I used your “do_shortcode($content)” and it worked like a charm!
    Of course I had to figure out how to include that in the code in my theme, but got it on the first try.

    In case it helps anyone else, my exact line of code is now:
    <?php echo '’ . do_shortcode( wpautop( wptexturize( term_description() ) ) ) . ”; ?>

    That may be theme specific, but other Woocommerce themes would be something similar. Thanks again!

    Reply
  61. maki says

    February 23, 2014 at 5:46 am

    Hey stephanie,

    this hack still works, thx !!!!! :)

    I tested it for tags and category description with WP 3.8.1

    Reply
  62. Pamela says

    February 26, 2014 at 10:12 am

    Hello,
    I put these two lines in the function.php to execute a shortcode in a text widget, which is in the featured area of my template.
    add_filter( ‘widget_text’, ‘shortcode_unautop’);
    add_filter( ‘widget_text’, ‘do_shortcode’);

    The text displays in the widget, but for some reason, the two columns of the template that are supposed to be under the featured area (where shortcode has been executed) are pushed to the bottom of the page.

    Is this ‘shortcode_unautop’ causing that to happen?

    Thanks for a helpful article.

    pam

    Reply
  63. Victor says

    March 8, 2014 at 1:41 am

    Hi, can tell me somebody how can I make shortcodes working in the header area, respectively in the title meta. I use a wp theme in which I add a shortcode in the title field – it works fine in the content area of the page, but in the header meta doesn’t show up the expected value but just the code – like [shortcode]. Any solution for this, maybe with an add_filter in the functions.php?

    Reply
  64. bj88 says

    June 17, 2014 at 6:55 pm

    It does not work for me to enable shortcode on excerpt with the following code

    add_filter( ‘the_excerpt’, ‘shortcode_unautop’);
    add_filter( ‘the_excerpt’, ‘do_shortcode’);

    Help :-)

    Reply
  65. manoj says

    January 7, 2015 at 12:44 pm

    it worked thanks!

    Reply
  66. Holger says

    February 25, 2015 at 1:51 pm

    Thanks so much ;) Works very well.
    But do you like to help me out with a more heavy thing?

    I want to have shortcodes in the WP Menu Custom Link URLs ;)

    There is a Javascript Solution in an a little outdated plugin.. but it should work by injection some php too

    Reply
  67. Albert says

    May 14, 2015 at 8:27 am

    Any idea how to get this to work for an email? I tried doing it like this:

    add_filter('user_registration_email', 'shortcode_unautop');
    add_filter('user_registration_email', 'do_shortcode');

    No luck.

    Reply
  68. Stepan says

    August 7, 2015 at 6:45 am

    How can I put my plugin’s widget in post&page content everywhere???

    I put it in this page, but it shows in the top of the page, can I put it for example after text in this page??

    please help me :-(

    Reply
  69. ashima says

    August 22, 2015 at 7:03 am

    Hye

    This is my website http://lawnsalonllc.com/ as you can see i have paste two shortcodes in two custom sections of footer, but they are not working as these sections are residing in theme-editor.php i.e these are custom sections

    i am very new to WordPress, can you please tell me how can i do that please?

    Ashima

    Reply
  70. Franco says

    May 2, 2016 at 5:06 am

    Excellent, saved my day!

    Reply
  71. Brian Shim says

    July 7, 2016 at 4:12 pm

    Great article. I used this technique to get Divi Builder content to show up in posts in archive pages.

    Reply
    • Brian Shim says

      August 11, 2016 at 2:36 pm

      One addition to this. I noticed that in archive pages, the tags were being stripped out using this technique. To get the tags back in, use this code:

      $content = get_the_content();
      $content = wpautop($content);
      $content = do_shortcode($content);
      echo $content;

      Hope this helps,
      Brian

      Reply
  72. Adam says

    September 10, 2016 at 3:55 pm

    Under “Template Files”, shouldn’t that be echo do_shortcode? Adding the word “echo” before “do_shortcode”? Thanks for the article!

    Reply
  73. Steven says

    October 5, 2016 at 9:11 pm

    Thanks for sharing this article. Very helpful but how about titles?

    Reply
  74. Newy Web says

    October 26, 2016 at 9:06 pm

    Hmm.. Trying to add this to a clients website on the footer, can’t seem to get it working. Will come back when I figure this out!

    Reply
  75. Eric says

    December 19, 2016 at 7:05 am

    Work like a charm: Thank you very much!

    Kind regards from Germany!

    Reply
  76. Daniel says

    January 29, 2017 at 9:08 pm

    hello. i have a question: is it possible to add shortcode support to my plugin via filter?

    i want my plugin to listen to all shortcodes, just as a normale page/post would behave. so i have my plugin code and while this code is executed i want it also to listen to any shortcode call which will happen inside.

    i hope you understand what i mean :) thanks!

    Reply
  77. Diana says

    March 29, 2018 at 9:03 am

    Works!

    Thank you so much. Two days search – and your post made my day !!! ))

    Reply
  78. PotapProrn says

    April 9, 2018 at 7:58 pm

    img
    http://www.imagebam.com/image/8a7351800376853
    http://imagestun.com/hosting/?v=26rzr.jpg

    http://www.litetext.com/ldl7
    http://fayloobmennik.cloud/7234207

    Reply

Leave a Reply Cancel reply

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

Footer

My Books

I’m a front end developer at Equinox OLI, working on open source library software. I was previously a freelance WordPress developer in higher education. You can get in touch here or on LinkedIn.

Copyright © 2023 Stephanie Leary · Contact