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 am trying to place a shortcode inside another shortcode within a page template, however the various attempts I've made seem to not do anything.

Here's how my code looks now -

<?php echo do_shortcode('[shortcode]' .$shortcode2. '[/shortcode]');?>

I've also tried these -

<?php echo do_shortcode('[shortcode]$shortcode2[/shortcode]');?>

<?php echo do_shortcode('[shortcode]{$shortcode2}[/shortcode]');?>

What am I doing wrong?

share|improve this question
    
The function that outputs the shortcode (i.e. the one called by add_shortcode) must be correctly written to allow this. It should contain the do_shortcode handler within its output. If you paste your shortcode functions code I can check it and provide a full answer. –  Simon Blackbourn Apr 9 '13 at 0:02

1 Answer 1

up vote 1 down vote accepted

Have you tried setting the output of the first do_shortcode inside the second call?

$output = do_shortcode('[first_shortcode]Some content[/first_shortcode]');
echo do_shortcode('[second_shortcode]'.$output.'[/second_shortcode]');
share|improve this answer
    
WOW AWESOME thanks! It worked –  mygm26 Apr 8 '13 at 23:59
    
Fantastic, do you mind hitting the check mark next to my answer so that others searching in the future can see your question was resolved? Happy coding. –  Andrew Bartel Apr 9 '13 at 0:00
    
This does work, but it shouldn't be necessary. If the shortcode functions are correctly written you can do echo do_shortcode( '[first][second][third]hello[/third][/second][/first]' ). –  Simon Blackbourn Apr 9 '13 at 0:24
    
@SimonBlackbourn I tried putting the shortcode inside the shortcode but it didn't work. I didn't write the shortcode functions so Im not sure what was done right or wrong. Thanks though. –  mygm26 Apr 9 '13 at 1:36

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.