Shortcode in a Template

Shortcodes in WordPress are bits of text you can use in the content area to invoke some kind of function to accomplish certain tasks. For example, video embedding in WP 2.9+ uses the shortcode. You can write your own shortcodes, and plugins often offer their functionality via shortcodes as well.

But what if you want to use a shortcode from within a template instead of with the content of a Post/Page? You can invoke it with a special function:

<?php echo do_shortcode("[shortcode]"); ?>


  1. User Avatar
    Permalink to comment#

    THANK YOU! I have needed to do this so many times and couldn’t find an easy way – I can’t believe it’s this simple. Whew!

    • User Avatar
      Antone Booker

      I need help how do I get my images to pop up in a thickbox with its description on WordPress vertical image menu or other plugins. I need a plugin that’s vertical scrolling with pop up image and description

    • User Avatar
      Permalink to comment#

      Hey Michelle,

      Can you tell me where the php code goes? I have tried to place it in the space that I need a form to show up but I get an error and the whole page disappears. Please help?

    • User Avatar
      Permalink to comment#

      Just what I needed. Thank you!

    • User Avatar
      Tim Brown
      Permalink to comment#

      For me it seemed to only work when I used one quote around the shortcode, not the double quote, like so.

      <?php echo do_shortcode('[shortcode]'); ?>
    • User Avatar
      Permalink to comment#

      @TimBrown – I think the reason that works is because most shortcodes have quotations in them to denote certain attributes of the shortcode like so:

      [contact-form-7 id="54" title="Contact Page Form"]

      When you put the shortcode in the php function the quotations end up being around the wrong parts.

      <?php echo do_shortcode("[contact-form-7 id="54" title="Contact Page Form"]"); ?>

      In the above code the quotations surround the “[contact-form-7 id=”, ” title=”, and “]” instead of what you want. So using the single quotes eliminates this so your double quotes surround the correct parts of the shortcode.

    • User Avatar
      Permalink to comment#

      how would i do it with this shortcode [supsystic-price-table id=11] ?

    • User Avatar
      Permalink to comment#

      @Timothy I am looking for a way to hard code a form on the homepage of a WordPress site. It looks like the code snippet you shared may help me do this. Do you happen to know where I would put this code snippet in the theme files? Your help is much appreciated!

  2. User Avatar
    Desarrollo de software
    Permalink to comment#

    Very ussefull, thanks for sharing =)

  3. User Avatar
    Permalink to comment#

    wow. this. just… works. ugh. Thank you a million as usual Chris. damn your head is full of useful crap!

  4. User Avatar
    Kris H
    Permalink to comment#

    I have a small addition – Using shortcode in a custom field.

    < ?php
        if (get_post_meta($post->ID, 'gallery', true)) {
        $shortcode = get_post_meta($post->ID, 'gallery', true);
        echo do_shortcode("$shortcode");
        } else { echo ''; }
    • User Avatar
      Permalink to comment#

      I am trying to do this for code that is already written to get a picture and description if it not NULL.

      I am trying to add code to check for a slideshow, photo, and description.

      Each of my slideshows have a ID#. I have added a field in the database that has the gallery ID # (gallery. This is my code but it is not working.

      300) {
      echo “”;
      else if ($height > 300) {
      echo “”;
      else {
      if ($width <= 300) {echo "”;
      else {echo “”;
      if ($page_row[description]) { ?>
      <?php $text = stripslashes($page_row[description]); echo $text;
      //echo splitchars($text, 80, "\n”);?>

      If I put a value in …….

      if ($page_row[gallery]) {echo do_shortcode(‘[slideshow id=1]‘);}

      everything works fine, but I need it to find which gallery goes with which member and place that gallery on the Page.

      Thanks, Linda

  5. User Avatar
    david swain
    Permalink to comment#

    I cant get this working, im trying to use it with the embed shortcode with content from a custom field, could you give an example of its usage?

  6. User Avatar
    david swain
    Permalink to comment#

    Found a solution!

    Should anyione be interested the solution is:

    if (!empty($full)) {
           $var = apply_filters('the_content', "[embed]" . $full . "[/embed]");
    		echo $var;

    where $full is the value of the url to be embed (eg from a custom field

    • User Avatar
      Permalink to comment#


      I used your solution, however I was running into problems with other filters applied to ‘the_content’… so after much searching… I finally came upon a better solution to this (see below) and wanted to save others the aggravation… :) (also posted this over on the forums)

      $wp_embed = new WP_Embed();
      $post_embed = $wp_embed->run_shortcode('[embed width="800"]' . $post_embed . '[/embed]');

    • User Avatar
      Permalink to comment#

      actually that example doesn’t make since to most…

      try this :)

      $wp_embed = new WP_Embed();
      $post_embed = $wp_embed->run_shortcode('[embed]your-video-url[/embed]');

    • User Avatar
      Permalink to comment#

      @david swain

      Thank you very much, saved me a lot of time.

  7. User Avatar
    Permalink to comment#

    for all who get a nasty PHP error after inserting the code in the original blogpost: you need to use single quotes, not the normal ones. Even more if the shortcode contains options.

    '[shortcode option="moo"]'

    • User Avatar
      Permalink to comment#

      Thanks @PipeSmokingMan, that made all the difference, Single Quotes not double.

    • User Avatar
      Permalink to comment#

      Thank you PipeSmokingMan!
      Thank you Chris!

    • User Avatar
      Permalink to comment#

      +1 for this guy

    • User Avatar
      Adrian Robertson
      Permalink to comment#

      Cheers for that PSM! Now working beautifully

    • User Avatar




    • User Avatar
      Craig A keefner
      Permalink to comment#

      Ditto. Quotes in the code instead of single quotes… Nice suggestion overall. I wanted to insert form on the content page template. Ended up with below. Excuse the HR height.

      <?php echo do_shortcode( 'For more information contact Kiosk Industry [contact-form to="" subject="General Contact Form"][contact-field label="Name" type="name" required="1"/][contact-field label="Email" type="email" required="1"/][contact-field label="Telephone" type="text"/][contact-field label="Comment" type="textarea"/][/contact-form]‘); ?>

  8. User Avatar
    Permalink to comment#

    Hi Chris awesome tip! i wanted to ask you something, i have a private shortcode and i wanna use it wrapping a table with all the private content but i cant get it to work, how can i wrap it?

  9. User Avatar
    Permalink to comment#

    I have this shortcode ” [ ultimate_carouselfree 1/] ” that’s working on pages and posts but I would like to display the video gallery on my theme’s homepage and none of the tricks above works. I literally SEE the code on my page even when I include id=1 at the end :(

  10. User Avatar
    Permalink to comment#

    Thanks “PipeSmokingMan”
    yes this code is trou:

    you must use (‘) not (“)

  11. User Avatar
    Permalink to comment#

    Cheers, very useful.

    Definitely watch your single and double quotes here….it got me for sure.

  12. User Avatar
    Permalink to comment#

    i love uuuu! solve my prob!

  13. User Avatar

    Can someone help , I have tried following all of the above steps, or at least I think I have

    in my index.php :

    the plugin is active and I am even using it within a page.

    Ive also tried with “echo” and without, but for some reason it just keeps outputting
    “[videoplayer file=”” /]”

    Can someone please tell me what I am missing ?

    • User Avatar

      “do_shortcode(‘[videoplayer file=”” /]” is what is missing above for the “index.php” section

  14. User Avatar

    I can not get the short code to work in the header!!! I want to use a short code i got from the cj wizrd so i can but 5 products in the header but it is not working. I tried what you said but it just all shows up as text like [cjwizard]table +saw,5,2446031+2185748+,120,3000,120,3000,USD,120,,,5,[/cjwizard]

    This is the code i used i did ‘ and ” like the guy above said to do

    any help would be great

  15. User Avatar
    Permalink to comment#

    Perfect, thanks so much for posting the solutions :)

  16. User Avatar

    @Danny (or anyone else),

    In the example above, where are you inserting the custom field?

  17. User Avatar
    Scott S.

    I’m trying to use this snippet for a facebook like shortcode on a custom template page. If I use the [fblikebutton] on a page it works fine, but if I try to use the php line with [fblikebutton] it just displays my shortcode along side the viewable text…any suggestions?

  18. User Avatar
    Permalink to comment#

    Thumbs up… Needed it badly.

  19. User Avatar
    Permalink to comment#

    Ok, I’ve been searching far and wide for answers, and no one seems to be able to help. You seem knowledgeable about these things, so I’m hoping you can sort me out. Sorry if it’s too complex!

    I have a wordpress website with an image gallery on one of the pages. I installed a gallery plugin that lays out my images with thumbnails to one side and a “loading area” for a larger image. All I have to do is use the short code [photospace], and to get it to display a specific gallery (they’re divided by media type), just [photospace id=NUMBER]. But, when I hard code this into my page template, I can only use the short code once. If I repeat it to access the other galleries, they don’t function. Is there a reason this is happening or a way to fix it? Thank you!

  20. User Avatar
    Purushottam Kushwaha
    Permalink to comment#

    Its Really helpful!

    I have following code which is working partially while embedding in my custom page template. i m unable to resolve the issue since last 2 days
    Please help out.

    echo do_shortcode('[tabs tabid="tabID1" type="vertical" effect="fade"
              [tab]test for tabbed content[/tab]');
              echo do_shortcode('[tab]this is something i need[/tab][/tabs]');

    The problem I think may be of closing tag ([/tabs]);
    I tried many combinations , but got nothing.

    • User Avatar
      Permalink to comment#

      because of this code i solved my problem………Thank you so much !!!!!…..

  21. User Avatar
    Rachel Babble
    Permalink to comment#

    You’re my hero.

  22. User Avatar
    Permalink to comment#

    Thanks thanks thanks thanks thanks… so easy as well!! I was fretting about this for ages but that man.

  23. User Avatar
    Permalink to comment#

    I am trying to load a shortcode in my theme using:

    echo do_shortcode(‘[jwplayer param=”file=”″]’);

    but it keeps echoing out to the page and not getting the movie any ideas what I am doing wrong?

  24. User Avatar
    Permalink to comment#


    I tried it but it is not working for me. It’s just showing whatever i am passing as a shortcode.

    Can anyone help me quickly?


  25. User Avatar
    Permalink to comment#

    job done! :)

  26. User Avatar
    Permalink to comment#

    wau! this just made my day

  27. User Avatar
    Permalink to comment#

    I have been trying to add multiple short code in the same row..

    For example three price packages short code in same row.. That too wanted to include in php.,.

    Can we do that… Kindly give example.


    Is that correct? please help us

  28. User Avatar
    Permalink to comment#

    Sorry ! missed the code…

    <?php echo do_shortcode("[shortcode]"); ?>[pricing_table_shortcode columns="three" slug="p1"], [pricing_table_shortcode columns="three" slug="p1"], [pricing_table_shortcode columns="three" slug="p1"]?>
  29. User Avatar
    Permalink to comment#

    How can i check if the output of the shortcode is populated? im using this method and its great when theres a result but for a custom field that has no output ie an image i cant seem to be able to check that using a standard IF/ELSE statement. Can anyone offer any advice on this?


  30. User Avatar
    Permalink to comment#

    Thank you so, so, SO much!!!!!!

    You are an amazing man!

  31. User Avatar
    Permalink to comment#

    THANK YOU SOOOOOOO MUCH!!! THIS IS THE $@!* lol but seriously its awesome!! Thanks again

  32. User Avatar
    Permalink to comment#

    anyone know how to parse the content from inside enclosed shortcode tags. I need it for a conditional… if function – echo shortcode1, else echo shortcode2… having a helluvatime figuring this one out.

    • User Avatar
      Permalink to comment#

      For example something like this:

      if ( is_home() ) {
      echo do_shortcode(‘[shortcode1]’)
      else {
      echo do_shortcode(‘[shortcode2]’)

      Although I presume you’ve tried this… it seems to obvious ;)

  33. User Avatar
    Permalink to comment#

    If anyone is breaking their theme while implementing the code :

    replace the ” with ‘

    Ie. try this instead:

    I think it happens when you have apostrophes in the shortcode.

    Any enlightenment would be most welcomed?

  34. User Avatar
    Permalink to comment#

    Sorry the code didn’t appear in the above instead of this:
    <?php echo do_shortcode(“[shortcode]”); ?<

    Try this:
    <?php echo do_shortcode(‘[shortcode]’); ?<

  35. User Avatar
    Jonas Duri
    Permalink to comment#

    Ahhrrgg.. didn’t see that one first so I submitted the same snippet to the WordPress section recently :/
    Sry Chris for wasting your time :)

    btw this snippet is very usefull when you code a theme which uses the WooCommerce plugin and you don’t wanna mess with all these hocks and filters..

  36. User Avatar
    Permalink to comment#

    Worked like a charm !!! Thank you so much.

  37. User Avatar

    I have a PHP file which i added Custom Fields PHP options, and i want to add shortcodes to the end result which is a [member] info…[/member] which basically requires to be logged in to display. How can i get this to show up?
    [member]<?php the_field(‘price’); ?>[/member]
    Doesnt work…

  38. User Avatar

    I’m also trying to wrap some member only content inside a beginning and end shortcode in the template file. Any ideas?

    • User Avatar

      i added this to my functions.php file in my theme >>>

      add_shortcode( ‘member’, ‘member_check_shortcode’ );

      function member_check_shortcode( $atts, $content = null ) {
      if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
      return $content;
      return ‘Login’;

      below all the require_once section around line 25 – 30 maybe.

      But on my end im trying to make this shortcode work inside another php file = to a listing template.

  39. User Avatar

    After a lot of digging in the wordpress and php templates, i found this and this was so easy…….thanks a lot for this small piece of code but still very very useful.

  40. User Avatar

    Is there anyway I can insert shortcode into HTML?

  41. User Avatar
    Permalink to comment#

    How do I use shortcode in a template when there are 2 parts to the shortcode wrapped around some code. For instance creating custom fields and div content that are wrapped in [member] shortcodes [/member] to hide content from non-members

  42. User Avatar
    Permalink to comment#

    I have no idea what I’ve done (fiddled with some formatting in a page?), but suddenly all the shortcodes have stopped working… I don’t know where to start debugging, help! :)

  43. User Avatar
    Matthew Johnson
    Permalink to comment#

    This worked perfectly! Thanks a ton Chris, you’re a super genius.

  44. User Avatar
    Kelvin Castelino
    Permalink to comment#

    I would like to add a short code in the js file, where I modify a js file, but call this short code so it does the functionality necessary! Can this be done?

  45. User Avatar
    Travis Miller
    Permalink to comment#

    Chris, you are a genius, keep up the great work bro!

  46. User Avatar
    Permalink to comment#

    Hello all,

    I have been trying for days to get this to work according to the format on the codex [code]
    echo do_shortcode(‘[iscorrect]’.$text_to_be_wrapped_in_shortcode.'[/iscorrect]’);
    [/code] …
    What I need to include in the page template is a set of tabs, and then autofill using another short code. In desperation I have even taken out the text in the hope I can get the tabs to display (ie troubleshoot first, fix later) but no luck. I have even tried another tabs plugin with no luck. The plugin I am using is the WP Rollover-Tab: I am unable to get a response from the developer :(



    All I get is this printed (no tabs seen)
    [rollover-tab name=”tab1″][/rollover-tab][rollover-tab name=”tab2″][/rollover-tab]

    Part of the plugin syntax is mandatorty (no spaces between brackets

    I hope someone already has a fix for this. I read an earlier request for help in the comments for a very similar tabs shortcode problem but no reply to fix it.

  47. User Avatar
    Permalink to comment#

    This is the code that did not display from my comment
    echo do_shortcode(‘[rollover-tabs][rollover-tab name=”tab1″][/rollover-tab][rollover-tab name=”tab2″][/rollover-tab][rollover-tabs]’);
    ? >

  48. User Avatar
    Permalink to comment#

    This syntax does not work anymore:


    Double quotes ( ” )are replaced with single quote ( ‘ )

  49. User Avatar
    Mike King
    Permalink to comment#

    Thank you! This snippet saved my butt BIG TIME!

  50. User Avatar
    Permalink to comment#

    Can you post the code again please? It does not print out on the screen!

    For this plugin I MUST have “” as in
    [rollover-tab name=”tab1″][shcd cntnt1=text1][/rollover-tab][rollover-tab name=”tab2″]
    otherwise there are errors

    I made a little progress with using the RolloverTab plugin by running all the shortcodes in ONE long line for all 5 tabs (as in …
    echo do_shortcode (‘[tabs][tab1][content1][/tab][tab2][content2][/tab][/tabs]’);
    but now all the content shows in all the tabs

    Any thoughts/suggestions ?

  51. User Avatar
    Aussie Domainer
    Permalink to comment#

    Thank you! Didn’t think this would be possible! I was trying to insert the plug ins code into the main page. Nice one!

  52. User Avatar
    Permalink to comment#

    Chris…’s awsome, thanx a lot man,…..

  53. User Avatar
    Permalink to comment#

    Does using a shortcode also help for loading efficiency? say you make a shortcode of what appears on more than one page, but not in the header to appear on all pages?

  54. User Avatar
    Glen Wheeler
    Permalink to comment#

    I’m not so sure this is correct? Should’nt it be

    and not

    Using quotations does not work when adding shortcodes in WordPress 3.0 templates

  55. User Avatar
    Permalink to comment#

    Thanks man!

  56. User Avatar
    Permalink to comment#

    thanks! you saved my time!! thanks alot

  57. User Avatar
    Permalink to comment#

    thanks man, it really helped me to solve a serious issue on a client site.

  58. User Avatar
    Permalink to comment#

    Hi I have inserted a slider using the shortcode php script provided could any one tell me how I would center the slider that the shortcode is grabbing. I have tried everything.

    Site is

    Many thanks in advance

  59. User Avatar
    Glen Wheeler
    Permalink to comment#

    You could add #bannerRotatorParent_18262 to your stylesheet and do


    margin: 0 auto;

    that would work I guess…bit messy but would work

  60. User Avatar
    Glen Wheeler
    Permalink to comment#



    margin: 0 auto;

    to your stylesheet. Use a # at the start of bannerRotatorParent_18262 i think this comment area is removing it

    that should work

    • User Avatar
      Permalink to comment#

      Hi Glen,

      Can seem to make that work. have added to css but not working. Can you offer any other advice?

      Many Thanks.

  61. User Avatar
    Glen Wheeler
    Permalink to comment#

    Maybe I can help if you contact me matey? @glenwheeler on twitter or onesixtwoltd on skype hope chris doesn’t see this as advertising myself.


  62. User Avatar
    Craig Mische
    Permalink to comment#

    Thank you very much to all of you for your help. I’ve been trying to figure out a solution to this for quite some time.

  63. User Avatar
    DlaGeeka Filmy Recenzje
    Permalink to comment#

    Wow! That simple? I can’t believe it :) Very useful tips as usual. Thanks for posting it.

  64. User Avatar
    Permalink to comment#

    Hi, I have problem with this my shortcode is
    [ninja-popup ID=1]popup[/ninja-popup],
    I tried this:

     ?php echo do_shortcode('[ninja-popup ID=1]cool[/ninja-popup]'); ?

    But didn’t work…please how to do it?
    Thank you

  65. User Avatar
    Permalink to comment#

    Googled this, found your post, spot on Chris.

    Thanks for this!


  66. User Avatar
    Permalink to comment#

    Thanks so so much.. It Works for me!!!!!!!!

  67. User Avatar
    Permalink to comment#

    This falls under the category of code I never try to memorize. I’ve been to this page more times than I can count. Thanks for a great site and community.

    • User Avatar
      Archie Makuwa
      Permalink to comment#

      Hahaha… same here, I have even booked marked it.

  68. User Avatar
    Permalink to comment#

    Very useful! Thanks!
    Another solution though not as easy is to use the short code on a normal page then view that source code and copy it onto your template.

  69. User Avatar
    Permalink to comment#

    hey nice it works but how can I anchor a shortcode in my header file

  70. User Avatar
    Brad Dalton
    Permalink to comment#

    You can also execute the shortcode using a custom function with conditional tag and hook it into place in your child themes functions.php file which is a better way to customize your theme rather than edit your parent themes template files.


    function display_slider_header_home() {
    if (is_home()) {
    echo do_shortcode(‘[easingsliderlite]’);
    add_action(‘genesis_header’, ‘display_slider_header_home’);

    • User Avatar
      Permalink to comment#


      I’m trying to add a Custom Slider to my Genesis child theme. The only instructions from the Slider folks are to add in the php somewhere.

      <?php echo do_shortcode('[all_around id="1"]'); ?>

      I tried placing this in home.php and broke the site. Is there a different method to add this in Genesis? I saw some folks adding shortcodes through the functions.php file, and your method above seems close. …



  71. User Avatar
    Permalink to comment#

    Thanks, Chris!

  72. User Avatar
    Permalink to comment#

    I’m trying to make a page have tabs without having to put the shortcodes into the tinyMCE.

    I want to have this:

    Tab 1 (Home)
    within this tab will be the content I can enter into the TinyMCE in the wordpress backend.
    Tab 2 (Media)
    within this tab will be an image slider and a video embed area
    Tab 3 (Reviews)
    within this tab will be the comments section.
    Tab 4 (Reqest a Quote)
    within this tab will be a form for visitors to fill out

    can this be done using the methods above. I am having some trouble

  73. User Avatar

    works great, I used single quote instead of double quotes and that solved the initial issues i had.

  74. User Avatar
    Steven Schafer

    Ok, I hope someone out there can answer a few questions and point me in the right direction. I have a site: —it is very dependent upon a 3rd party idx (real estate listings) plug in that uses short code.

    I have been on a mission to decrease page load time. One of the 7 errors I get on Yslow is that i need to:

    Grade F on Put CSS at top
    There are 7 stylesheets found in the body of the document…………………

    This plug in is a short code item, so it’s move the short code or nothing at all. Each page (about 300 of them have their own short code id). Any ideas how I can pull this off and decrease page load time.

  75. User Avatar
    php echo do_shortcode('[soundcloud]'.$album_url.'[/soundcloud]'); ?> 

    few people above trouble with closing to here this might help ^^

    thanks Chris! .

    • User Avatar
      Permalink to comment#

      I get that you would do the code like this – thanks. But what if you have a lot of content code like when you need to pull in many ACF fields.

      So I want to wrap a lot of content in my accordion shortcode. If I had just one ACF it would look like this –

      echo do_shortcode( '[su_accordion]
      [su_spoiler title="Read more" style="fancy"]'  . get_field('description') . '[/su_spoiler]
      [/su_accordion]' );

      And this works fine.

      But my code actually is long and looks like this before wrapping in an accordion:

      echo '<strong>Topic area:</strong>';
      $values = get_field('topic_area');
          echo '';
          foreach($values as $value)
              echo '' . $value . '';
          echo '
      echo '';

      How do I get all of this “between” the opening and closing shortcode?

  76. User Avatar
    Geoffrey Hunter

    Yes! Thanks for this, exactly what I needed for processing shortcodes in custom-made php files.

  77. User Avatar
    Bobby Tonnies
    Permalink to comment#


    I know 100 people already said it.

    But I needed this so bad.

    Worked perfectly.

    Thanks CHRIS!!!!

  78. User Avatar
    Permalink to comment#

    Awesome! Love all of your advise and you have saved me once again :)

  79. User Avatar
    Brad Dalton
    Permalink to comment#

    Easily execute any shortcode in any template without even adding it to the template file using a custom function in your child theme.

    Use a conditional tag and theme specific hook for even more control.

    function wpsites_gravity_form_before_content() {
    if (is_category()) {
    echo do_shortcode('[gravityform id=1 title=false description=false ajax=true]');
    add_action('genesis_before_post', 'wpsites_gravity_form_before_content');
  80. User Avatar
    Permalink to comment#

    Yahoooo. Simple! But works! Thanks a lot.

  81. User Avatar
    Permalink to comment#

    I had to bookmark this page. I can never remember how to do this. Thanks Chris, you’ve saved my butt many times.

  82. User Avatar
    Permalink to comment#

    another big THANK YOU from me!

  83. User Avatar
    Permalink to comment#

    Thank you so much :)

  84. User Avatar
    Martin Oxby
    Permalink to comment#

    Fab! The quickest, most succinct answer. Trying to get an audio plugin to work from a template but it only has a shortcode option, but I don’t want it in posts, so including it in footer.php :-)

    Thank you!

  85. User Avatar
    Permalink to comment#


    Thanks for the short but incredibly valuable tutorial.

    I seem to be having a problem adding a shortcode which has an additional characteristic. Can anyone advise on how I would add this into my template file please…

    [myshortcode height="200"]


  86. User Avatar
    Edd Biel
    Permalink to comment#

    You’re actually amazing Chris! haha, EXACTLY what i was looking for to implement a slider into my template, and not a page/post. Thanks bro :)

  87. User Avatar
    Permalink to comment#

    wondering how I would pass shortcode in query results to template..
    echo do_shortcode($datarow->shortcode);
    this works .. thanks

  88. User Avatar
    Tyler Steimle
    Permalink to comment#

    Chris, you probably hear this a bunch, but I’ll bet it never gets old: your website is an amazing resource that I am thankful every week for. Keep ’em comin’—great job!

    • User Avatar
      Chris Coyier
      Permalink to comment#

      Thanks for the kind words Tyler. I do my best to keep comment threads on-topic for people finding articles like this, so don’t take offense, but I’m going to bury this thread.

  89. User Avatar
    Doan Xuan Bao
    Permalink to comment#

    After struggling with calling API function. It’s still getting error. I’m lucky finding your post! My API function does support shortcode. With your tutorial, it works perfect now! Wow! You made my day! Whew! What a time saver! Thanks so muck for the post!

  90. User Avatar
    Permalink to comment#

    AHHH Thank you! So easy!

  91. User Avatar
    Permalink to comment#

    Legend. I was fed up just seeing my shortcodes appear on the page willing them to show the proper output

  92. User Avatar
    Permalink to comment#

    hi. I want shortcode show in wordpress admin panel? for example contact form 7 forms show in admin panel. thank you.

  93. User Avatar
    Permalink to comment#

    thanks, you save my life :D

  94. User Avatar
    Steve Zelle
    Permalink to comment#

    Thanks—worked great. Much appreciated.

  95. User Avatar
    Permalink to comment#

    You are my hero. Plain and simple. Thank you for this and at least a dozen other things I’ve learned from you!

  96. User Avatar
    Permalink to comment#

    Four years later and it really helped me out. Thanks!

  97. User Avatar
    Permalink to comment#

    THANKS! My shortcodes kept coming up as html! This fixed it! Eeeeeexcellent!

  98. User Avatar
    Mel Reiff Hill
    Permalink to comment#

    Thanks, that did the trick!

  99. User Avatar

    Dear Sir,
    I am trying to insert a short code for audio to play at home page .
    ?php echo do_shortcode( [audio mp3=""][/audio] ) ?>
    but my site then never loads into the browser and gives a compete black webpage. same short code when i insert into the woocomerce product page it gives the good result and play audio when clicked . Please help asap

  100. User Avatar

    I was stuck for like 3 days on my project and saw this! Thank you again!

  101. User Avatar
    Permalink to comment#

    Chris I think it’s worth changing your demo to use single quotes. So many shortcodes nowadays on the more feature-rich wordpress themes have double quoted attributes within them and it just caught me out.

  102. User Avatar
    Permalink to comment#

    Hi, I have WP v. 3.9.1. and Simple Staff List v 1.15 plugin.

    I created a person in the wp-admin. Then I used

    php echo do_shortcode("[simple-staff-list]");

    which writes out the person. Nice, but I have a special div structure prepared for this, so it would be nice to have access to the individual parameters (name, email, phone, …), so I can place them at a correct place.

    I tried the following:

    php echo do_shortcode('[staff_loop]'); 
    img class="staff-member-photo" src="[staff-photo-url]" alt="[staff-name] : [staff-position]"
    div class="staff-member-info-wrap"
    php echo do_shortcode('[staff-name-formatted]'); 
    php echo do_shortcode('[staff-position-formatted]'); 
    php echo do_shortcode('[staff-bio-formatted]'); 
    php echo do_shortcode('[staff-email-link]'); 
    php echo do_shortcode('[/staff_loop]'); 

    also the original code without echo ... from the Templates, but it always results in a plain text as if I intended to write out "[staff_loop]" on my page. See the attachement. The person above the text is the php echo do_shortcode("[simple-staff-list]"); code.

    Where am I making the mistake? Thanks!

  103. User Avatar
    neon emmanuel

    Hmm nice tips bro, now my site looks perfect, I think I prefer short codes enabled plugin to widget type plugin

  104. User Avatar
    Permalink to comment#

    how do i use shortcode inside of a shortcode in php… lets say i have a shortcode that returns name of a city [city] and then i have another shortcode that would return list of coffee shops in a particular city which would need to be set up like this… [search=”coffee” location=”[city]”] … if someone has anyideas on how to display that above shortcode in php where there is shortcode inside of a shortcode i would really appreciate this. thanks

  105. User Avatar
    Andrew Rogers
    Permalink to comment#

    THANKS! I used this – echo do_shortcode(‘[property_flyer urlonly=’yes’]’); and it was not working. After I was your post I replaced my ” with “” and presto it worked – echo do_shortcode(“[property_flyer urlonly=’yes’]”);

  106. User Avatar
    Permalink to comment#

    I want a code that it will show the original photo of the featured image when when the “x” field is empty, and if it isn’t then it will not shot the featured image.

    At another point of the single post I want to show the “x” when it not empty, and it’s empty then it will show nothing.

    Also, the “x” field must support the display of shortcodes (A gallery of nextgen with shortcode), embed tweet and Instagram photos.

    I have created this code that I show on the place of the featured image the “x” field when it has a record inside but I have problems with tit and it doesn’t tweet and Instagram photos. It also has conflicts with the shortcodes.

    Can someone help me with those 2 codes so I can make them work right?

  107. User Avatar
    Permalink to comment#

    This is great! However…

    There seems to be an issue with lightbox. I’ve used this method on a few types of gallery plugins and the ones that use lightbox don’t work. Specifically, the thumbnail images display, but once clicked nothing happens.

    Any thoughts on this?

  108. User Avatar
    Permalink to comment#

    Awesomeness!! Thank you

  109. User Avatar
    Permalink to comment#

    This is for use shortcode in template file. If you want to use shortcode in post editor use the following.

  110. User Avatar
    Permalink to comment#

    Many Thanks! This just saved my bacon.

  111. User Avatar
    Permalink to comment#

    Thank you! This code worked wonders – just what I was looking for.

  112. User Avatar
    Brad Dalton
    Permalink to comment#

    Not an efficient way to execute short codes.

    What you should do is use the callback function rather than do_shortcode.

  113. User Avatar
    Peter Shields
    Permalink to comment#

    This is the shortcode I need to use in the header.php file in order to get the counter working,
    [custom_clocks id=”1″ set_time=”3600241″]

    However, replacing the [shortcode] in the code above results in a broken site.

    Currently, the code looks like

    Have spent the better part of an afternoon trying to figure out why this is not working, if anyone could point me in the right direction would be fantastic.

    • User Avatar
      Brad Dalton
      Permalink to comment#

      I suggest you try your theme forums or forums. css-tricks also have forums as well. I would also use the function call in the header rather than the short code.

  114. User Avatar
    Peter Shields
    Permalink to comment#

    Ok Brad ill take a look there too, Thought it might be something quick and simple, this is a complete learning curve for me as I have only had a couple of days experience with WordPress and this is the first page I came across with any sort of beginner explanation after a fair bit of searching :)

  115. User Avatar
    Permalink to comment#

    Hi, I have this code entered twice, once in header.php and once in footer.php

    Its the same code! Ive checked many times. In the footer it just displays [name_of_shortcode]

    Any ideas?

  116. User Avatar
    Permalink to comment#

    have used s2 member shortcode in php file below is the code that i have used in php file

    <?php echo do_shortcode(‘[s2Member-Profile /]’);

    see for the way it look like . but my issues is with password field, the two text fields can be different, and the password is still changed and also Password strength indicator not working

  117. User Avatar

    My shortcode is [ninja_form id=5], I have tried all the above methods to convert this shortcode to html format in html editor of visual composer, but is diplayed as string .
    I also want to add a background image to the form . Anyone please help.

  118. User Avatar
    Permalink to comment#

    This is a great tip, but where do I insert this function exactly? Directly in the Page or in Template Editor?

    PS I am using a template from Envato Market.

  119. User Avatar
    Permalink to comment#


  120. User Avatar
    Permalink to comment#

    Thanks Still working

  121. User Avatar
    Permalink to comment#

    i solved my problem with this line of code

  122. User Avatar
    Permalink to comment#

    Been searching this all over the web, but how do you make this work with an opening and closing shortcode.

    I want to use [member] and [/member] in my php code, but I can’t figure it out

  123. User Avatar
    Permalink to comment#

    I am trying to add a shortcode into a pricing table theme. So if someone clicks the enquire button a pop up window comes up.

    The shortcode for the pop up window is [captainform id="885572" lightbox="1" url="" type="image"]

    and I have been told to do the above ie

    However I am unsure where abouts in the .php file I have to put it….could someone please point me in the write direction.

  124. User Avatar
    Permalink to comment#

    How can i use [member] and [/member] in my php code with echo do shortcode?

  125. User Avatar
    Musarrof, Freelancer

    Hay. Thank you so much for your help. As a new WordPress student. Really It’s very helpful for me.
    I bookmarked your post.

  126. User Avatar
    haftu abadi

    i migrate my website from Joomla to word press there are auto generated Archives,categories ,, recent post and comments on sidebar , i want to insert read more link could you help me please

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.