X

Creating nested shortcode concept

Visual Composer Review - editor

Surely I'm not the first but after recently being asked by a visitor about nested shortcodes I figure I would fool around with the idea. Adding this snippet to the functions.php of your wordpress theme will let you fool around with the following nested shortcode [link][my_text][/link]. No tricks just pass $content into do_shortcode() and works like a charm.


add_shortcode("my_text", "my_text");
function my_text() {
	return 'nested shortcode';
}

function my_link($atts, $content = null) {
	extract(shortcode_atts(array(
		"href" => 'http://'
	), $atts));
	return '<a href="'.$href.'">'.do_shortcode($content).'</a>';
}
add_shortcode("link", "my_link");
[link][my_text][/link]

Comments  Leave a Reply

  1. Thanks for this tip but if i may ask, what use can this nested shortcode be put to? I mean in what ways and how can it be used?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!