Shortcodes inside a shortcode - wordpress

I created a shortcode which display the employees, the HTML look somthing like that:

<ul class="employees">

<li><img src=""> <h5>name</h5> <p>description</p></li>
<li><img src=""> <h5>name</h5> <p>description</p></li>
..

</ul>

So I created 2 shortcodes:

[start_employee] - which contains <ul class="employee"> .. </ul>

[employee] - which contains content about the employee

And it should work like that:

[start_employee]
[employee img=".." name=".." description=".."] 
[employee img=".." name=".." description=".."] 
[/start_employee]

but when I put it in the wordpress editor the html look like that:

<ul class="employee">
[employee img=".." name=".." description=".."] 
[employee img=".." name=".." description=".."]
</ul>

I think I know why.. because the fuunction of start_employee contain:

return '<ul class="employee">'.$content.'</ul>';

What should I do that it read it as a shortcode?

Thank you.

Answers


Shortcodes do not automatically nest -- you have to call do_shortcode($content) yourself. See the caption_shortcode() example on http://codex.wordpress.org/Shortcode_API.


You have to use shortcodes recursively to get the result.

function start_employee($attr,$content){
          return '<ul class="employee">'.do_shortcode($content).'</ul>';
}
add_shortcode("start_employee","start_employee");

function employee($attr,$content){
          return '<li><img src=""> <h5>name</h5>; <p>description</p></li>';
}
add_shortcode("employee","employee");

If you have a recursive function set up, as in Cart66, you can do something like this:

echo do_shortcode('[hide_from level="membership" ]<strong>You may only order this item if you are a member. Become a <a href="http://yoursite.com/beta/member-log-in/">member</a>.</strong>[/hide_from]');
echo do_shortcode('[show_to level="membership"]'.do_shortcode('[add_to_cart item="'.$prefix.get_post_meta($post->ID,'_et_cart66_product_id',true).'" ]').'[/show_to]');

Need Your Help

Unable to set breakpoints in Chrome dev tools, version 26.0.1410.64 m

debugging google-chrome breakpoints google-chrome-devtools

I need to debug some JavaScript an' I use Chrome dev tools. I'm a newby in JavaScript (just started to learn a couple of days ago), an' at work I could set breakpoints via the Resources pane. But a...

NSURLConnection doesn't call delegate methods

iphone delegates nsurlconnection

I saw similar questions here, but I couldn't find solution to my problem.