Grow your CSS skills. Land your dream job.

Last updated on:

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]"); ?>

Comments

  1. 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!

    • 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

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

    • TGraphics
      Permalink to comment#

      Just what I needed. Thank you!

  2. Very ussefull, thanks for sharing =)

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

  4. 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 ''; }
    ?>
    • 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. 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. 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 http://www.youtube.com/watch?v=wLh6F7G7rPA) from a custom field

    • @davidswain

      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 wordpress.org forums)


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

    • 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]');

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

    like:
    '[shortcode option="moo"]'

  8. 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. 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. Thanks “PipeSmokingMan”
    yes this code is trou:

    you must use (‘) not (“)

  11. Permalink to comment#

    Cheers, very useful.

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

  12. lissa
    Permalink to comment#

    i love uuuu! solve my prob!

  13. Dave

    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="http://www.youtube.com/watch?v=ujwYaHwTH0A" /]”

    Can someone please tell me what I am missing ?

    • Dave

      “do_shortcode(‘[videoplayer file="http://www.youtube.com/watch?v=ujwYaHwTH0A" /]” is what is missing above for the “index.php” section

  14. 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. Permalink to comment#

    Perfect, thanks so much for posting the solutions :)

  16. Ken

    @Danny (or anyone else),

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

  17. 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. Assad
    Permalink to comment#

    Thumbs up… Needed it badly.

  19. 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. 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"
              headings="Basic|Demographic"]
              [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.

    • nitin
      Permalink to comment#

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

  21. Rachel Babble
    Permalink to comment#

    You’re my hero.

  22. Permalink to comment#

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

  23. Permalink to comment#

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

    echo do_shortcode(‘[jwplayer param="file="http://actionablebooks.com/wp-content/themes/actionablebooks/js/jwplayer/ABmovie.mp4"]‘);

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

  24. Permalink to comment#

    Hi,

    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?

    Thanks,

  25. Shreyo
    Permalink to comment#

    job done! :)

  26. dani
    Permalink to comment#

    wau! this just made my day

  27. 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. 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. Dan
    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?

    Thx.

  30. Bro
    Permalink to comment#

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

    You are an amazing man!

  31. AxIs
    Permalink to comment#

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

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

    • 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. 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. 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. 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. Mannie
    Permalink to comment#

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

  37. Jose

    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. I’m also trying to wrap some member only content inside a beginning and end shortcode in the template file. Any ideas?
    Thanks!

    • Jose

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

    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. Is there anyway I can insert shortcode into HTML?

  41. 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. cosmin
    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. This worked perfectly! Thanks a ton Chris, you’re a super genius.

  44. 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. Chris, you are a genius, keep up the great work bro!

  46. JonnyDee
    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 :(

    [code]

    [/code]

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

    Part of the plugin syntax is mandatorty (no spaces between brackets
    [code]
    [/rollover-tab][rollover-tabs]
    [/code]

    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. JonnyDee
    Permalink to comment#

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

  48. Permalink to comment#

    This syntax does not work anymore:

    Updated:

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

  49. Thank you! This snippet saved my butt BIG TIME!

  50. JonnyDee
    Permalink to comment#

    Daniyal,
    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 …
    php
    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. 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. Salih
    Permalink to comment#

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

  53. 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. 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. Permalink to comment#

    Thanks man!

  56. voji91
    Permalink to comment#

    thanks! you saved my time!! thanks alot

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

  58. Eddie
    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 http://www.thetheatreacademy.com/test

    Many thanks in advance

  59. Glen Wheeler
    Permalink to comment#

    You could add #bannerRotatorParent_18262 to your stylesheet and do

    bannerRotatorParent_18262{

    margin: 0 auto;
    }

    that would work I guess…bit messy but would work

  60. Glen Wheeler
    Permalink to comment#

    Add

    bannerRotatorParent_18262{

    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

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

    Thanks,
    Glen

  62. 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. Wow! That simple? I can’t believe it :) Very useful tips as usual. Thanks for posting it.

  64. jain
    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. Dennis
    Permalink to comment#

    Googled this, found your post, spot on Chris.

    Thanks for this!

    :)

  66. Sanju
    Permalink to comment#

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

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

  68. Colby
    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. Sandeep
    Permalink to comment#

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

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

    Example:

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

    • Permalink to comment#

      Brad-

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

      Thanks!

      -Dan
      I

  71. Permalink to comment#

    Thanks, Chris!

  72. Andy
    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. kingston20

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

  74. Ok, I hope someone out there can answer a few questions and point me in the right direction. I have a site: http://www.southjerseyhomes.info. —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

    http://www.idxre.com/idx/css/carousel_thumbscroll_atlas.css?…

    http://www.idxre.com/idx/lib/javascript/livepipe-ui/css/window.css?…

    http://www.idxre.com/idx/externalServices/views/css/ihf_atlas_wp620.css?…

    http://www.idxre.com/idx/externalServices/views/css/ihf_atlas_wp620_blue.css?…

    http://www.idxre.com/idx/css/modalPhotoCarousel.css?…

    http://www.idxre.com/idx/externalServices/views/css/ihf_organizer_bar.css?…

    http://www.idxre.com/idx/css/ihf_v7_1_blue.css?…

    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. php echo do_shortcode('[soundcloud]'.$album_url.'[/soundcloud]'); ?> 

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

    thanks Chris! .

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

  77. Amazing.

    I know 100 people already said it.

    But I needed this so bad.

    Worked perfectly.

    Thanks CHRIS!!!!

  78. Michael
    Permalink to comment#

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

  79. 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. Akhil
    Permalink to comment#

    Yahoooo. Simple! But works! Thanks a lot.

  81. 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. NIKI
    Permalink to comment#

    another big THANK YOU from me!

  83. Permalink to comment#

    Thank you so much :)

  84. 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. Cody
    Permalink to comment#

    Hi

    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"]

    Thanks

  86. 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. phil
    Permalink to comment#

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

  88. 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!

    • 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. 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. Yvonne
    Permalink to comment#

    AHHH Thank you! So easy!

  91. Colin
    Permalink to comment#

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

  92. amir
    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. mohsen
    Permalink to comment#

    thanks, you save my life :D

  94. Thanks—worked great. Much appreciated.

  95. Lisa
    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. Permalink to comment#

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

  97. Richard
    Permalink to comment#

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

  98. Thanks, that did the trick!

  99. Amit

    Dear Sir,
    I am trying to insert a short code for audio to play at home page .
    ?php echo do_shortcode( [audio mp3="http://mysite.com/english/wp-content/uploads/2014/03music1.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. Louise

    OH MY GOD THIS WORKED! THANKS!
    I was stuck for like 3 days on my project and saw this! Thank you again!

  101. 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. Tina
    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]'); 
    div
    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. neon emmanuel

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

  104. Sohin
    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. 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. Alex
    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. Lee
    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. Taryn
    Permalink to comment#

    Awesomeness!! Thank you

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".