Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

Thanks!

Austen

share|improve this question
3  
Post your code please. –  s_ha_dum Jan 31 '13 at 15:34
    
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! –  Austen Osborne Jan 31 '13 at 15:39
    
@AustenOsborne updated your question with a sample of your code –  Bainternet Jan 31 '13 at 15:42
    
Your theme or a plugin is breaking this, almost certainly. –  s_ha_dum Jan 31 '13 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. –  Austen Osborne Jan 31 '13 at 17:09
show 2 more comments

2 Answers

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

[tabs][image][/image][image][/image][/tabs]

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!

share|improve this answer
    
Thanks Matt - makes sense, I'll give it a bash! Austen –  Austen Osborne Mar 6 '13 at 19:18
add comment

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]"); ?>
content
<?php echo do_shortcode("[/expand]"); ?>

you have to redesign your shortcode to something like this

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

and use a separate shortcode for closing the content off.

Shortcodes are very well explained in the Shortcode API

share|improve this answer
    
Thanks Kim - sorry I didn't see this reply until just now. I'll take a closer look now that the rush is off. –  Austen Osborne Mar 6 '13 at 19:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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