3

I wonder if is it possible to have a shortcode inside another one?

My scenario is this:

I create a shortcodes to display content into columns so I can manage the layout of the page more easily. Now the problem comes, when I try to use for sample nextgen gallery into one of those shortcodes. For some reason it just generates the shortcode as plain text.

Any idea why?

I will show you the code I'm using for the shortcode maybe it helps:

 // Column ShortCode Description
function column_scdescription($atts, $content="null") {
    return '<div class="description">' .$content . '</div> <!-- description ends here -->';
}
add_shortcode ("product-description", "column_scdescription");

Thanks in advance.

2 Answers 2

8

I usually apply the_content filters to $content to do this. I think you can aslo use do_shortcode($content);

// Column ShortCode Description
function column_scdescription($atts, $content="null") {
    return '<div class="description">' .apply_filters('the_content', $content) . '</div> <!-- description ends here -->';
}
add_shortcode ("product-description", "column_scdescription");

Read up on Nested Shortcodes in the codex.

0
4

'you can use the do_shortcode() wp function

function column_scdescription($atts, $content="null") {
    return '<div class="description">' . do_shortcode($content) . '</div>';
}
add_shortcode ("product-description", "column_scdescription");
2
  • does it work only if inside there is a shortcode right? if there plain text would it work? thanks for answer! Commented Dec 1, 2011 at 2:03
  • 1
    if there isn't a shortcode inside it will return as plain text.
    – Ijaas
    Commented Dec 1, 2011 at 2:13

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.