Shortcodes inside a shortcode - wordpress

后端 未结 3 1280
攒了一身酷
攒了一身酷 2020-12-05 07:20

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

相关标签:
3条回答
  • 2020-12-05 07:49

    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");
    
    0 讨论(0)
  • 2020-12-05 07:50

    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.

    0 讨论(0)
  • 2020-12-05 07:50

    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]');
    
    0 讨论(0)
提交回复
热议问题