shortcode inside another shortcode

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.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

‘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");


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x