The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Insert shortcodes inside attributes of other shortcodes (7 posts)

  1. Andrés Sanhueza
    Posted 6 years ago #

    Is there any way to be able to insert shortcodes (and other similar markup) inside the attributes of another (custom made) shortcode?

  2. MichaelH
    Posted 6 years ago #

    More of a question than an answer, but if you could parse out that shortcode from your shortcode then couldn't you use do_shortcode inside your function?

  3. Andrés Sanhueza
    Posted 6 years ago #

    Seems that only works with do_shortcode($content) and not with other attributes, but perhaps I forgot something.

  4. MichaelH
    Posted 6 years ago #

    As an example this works for the List Category Posts plugin http://wordpress.org/extend/plugins/list-category-posts/:

    Here's the shortcode:

    [myshortcode fun=yes other_shortcode=catlist id=1 numberposts=5)]

    here's the function:

    function myshortcode($atts){
        'fun' => 'no fun',
        'other_shortcode' => '',
        'id' => '',
        'numberposts' => ''
        ), $atts));
      echo 'Is this fun? ' . $fun;
      $newsc =  '['.$other_shortcode.' id='.$id.' numberposts='.$numberposts.']';
      echo do_shortcode($newsc);
    add_shortcode('myshortcode', 'myshortcode');
  5. MichaelH
    Posted 6 years ago #

  6. Andrés Sanhueza
    Posted 6 years ago #

    It works but I don't want to limit the attribute to a single shortcode. More like when do_shortcode is used in the content of an enclosing shortcode.

  7. MichaelH
    Posted 6 years ago #

    Missed this before, but according to Shortcode_API

    The shortcode parser correctly deals with nested shortcode macros, provided their handler functions support it by recursively calling do_shortcode():

    But then there is this trac ticket http://core.trac.wordpress.org/ticket/10082 that describes problems with nested shortcodes.

Topic Closed

This topic has been closed to new replies.

About this Topic