I have been using shortcodes in my templates successfully, apart from when a closing tag is required to wrap some other code or content.

The problem is that the closing tag, eg [/shortcode], doesn't get processed, and is simply printed to screen as plain text.

Am I missing something obvious?



  • 3
    Post your code please.
    – s_ha_dum
    Jan 31, 2013 at 15:34
  • 1
    Hi - it happens to any closing shortcode tags called by the do_shortcode function. I've tried single and double quotes, multiple brackets and anything else I could think of! Jan 31, 2013 at 15:39
  • @AustenOsborne updated your question with a sample of your code
    – Bainternet
    Jan 31, 2013 at 15:42
  • Your theme or a plugin is breaking this, almost certainly.
    – s_ha_dum
    Jan 31, 2013 at 15:43
  • Hi again, and thanks. I've removed the calls to the shortcodes for now as they don't work. I'm having to work around it with a bunch of custom fields into which I'm placing the shortcodes, and even then it's hit or miss. An example of the closing tag not working would be: <?php echo do_shortcode("[/expand]"); ?> - this should generate a span to close off a collapse-o-matic accordion, but it just prints to page. Thanks. Jan 31, 2013 at 17:09

2 Answers 2


The reason

echo do_shortcode("[/expand]");

is not working is because [/expand] is not a valid shortcode on it's own. The combination of [expand] and [/expand] is valid so

echo do_shortcode("[expand] some content [/expand]");

should work as intended. If you want to use this way of seting things up

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

you have to redesign your shortcode to something like this

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

and use a separate shortcode for closing the content off.

Shortcodes are very well explained in the Shortcode API

  • Thanks Kim - sorry I didn't see this reply until just now. I'll take a closer look now that the rush is off. Mar 6, 2013 at 19:17

Hey i found a workaround that I think works:

What I was doing before was probably like you guys. The structure as if I was in the WordPress Editor would look like this


Which in the template on first try looked like:

<?php echo do_shortcode('[tabs]');
echo do_shortcode('[image]'. code for generating image .'[/imagetab]');
echo do_shortcode('[image]'. code for generating image .'[/imagetab]');
echo do_shortcode('[/tabs]'); ?>

Which worked except the closing shortcode would just display as text and not close off the rest of everything. The workaround that seems to work for me is to do the same thing as I did in the [image] [/image] section, only executing the whole thing in one line, looking like this

<?php echo do_shortcode('[tabs]'.'[image]'. code for generating image .'[/imagetab]'.'[image]'. code for generating image .'[/imagetab]'.'[/tabs]'); ?>

I'm still pretty green at all this, so there is probably a better more elegant way to do this. but it seems to work for me. I hope this helps someone, if anyone finds a better way be sure to let me know!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.