• Hi!

    I have another question for you guys. Is it possible to use Shortcake and nested shortcodes?

    An example: right, now, I’m trying to create a shortcode that is a wrapper for another shortcode (Tablepress [table] shortcode). It’s a shortcode that wraps the [table] shortcode into a div with some custom classes.

    So, I’m using do_shortcode inside the function that renders the shortcode. On the frontend, it works great, but at the backend we don’t get a visual representation of the shortcode, we just get the [table] shortcode string.

    We’re using this piece of code:

    $html = '<div class="table-wrapper" id="'. $id .'" responsive="'. $responsive .'">';
    $html .= do_shortcode( '[table id="'. $id .'" responsive="'. $responsive .'"]' );
    $html .= '</div>';
    
    return $html;

    This is the expected behavior for nested shortcodes, or maybe something particular to Tablepress’ [table] shortcode? Or am I doing something wrong?

    Thanks!

    https://www.ads-software.com/plugins/shortcode-ui/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Daniel Bachhuber

    (@danielbachhuber)

    Is it possible to use Shortcake and nested shortcodes?

    It’s not, no. Here’s the existing Github issue. There likely won’t ever be nested UI for editing shortcodes, but shortcodes like Tablepress will need to produce their own UI for managing complex features.

    Thread Starter Diego de Oliveira

    (@diegoliv)

    Hi, Daniel,

    I don’t have a problem with nested UI’s. The way shortcake works right now is great. I have created a set of fields that passes the necessary attributes to the [table] shortcode, so the issue is not with Shortcake’s UI. I just wanted to render the [table] shortcode inside the Shortcake preview (this is why I’m using do_shortcode), but it’s rendering [table] as a shortcode string instead. Using do_shortcode inside another shortcode is the expected approach from the Shortcodes API on Codex:

    If the enclosing shortcode is intended to permit other shortcodes in its output, the handler function can call do_shortcode() recursively:

    function caption_shortcode( $atts, $content = null ) {
       return '<span class="caption">' . do_shortcode($content) . '</span>';
    }

    This is basically what I’m doing.

    So, the nested shortcode being rendered as a normal string inside a Shortcake preview is the defaul behavior? Just want to make sure we can’t do anything about it.

    Thanks again for your help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Nested Shortcodes’ is closed to new replies.