Using a custom shortcode from within the template of a shortcode plugin

If I understand it correctly, inside the shortcode template, you could do something like this:

echo do_shortcode( '[ta-intentclicks-link url="' . esc_url( $list_item['link'] ) . '"]Visit website[/ta-intentclicks-link]' );

But then, instead of having to use do_shortcode(), you could actually simply call the shortcode callback from the (shortcode) template ( which then eliminates the need to find and parse shortcodes in the content or the first parameter for do_shortcode() ):

  • If you registered the shortcode like so:

    add_shortcode( 'ta-intentclicks-link', 'my_shortcode' );
    function my_shortcode( $atts = array(), $content = null ) {
        $atts = shortcode_atts( array(
            'url' => '',
        ), $atts );
    
        if ( ! empty( $atts['url'] ) ) {
            return sprintf( '<a href="%s" target="_blank">%s</a>',
                esc_url( $atts['url'] ), esc_html( $content ? $content : $atts['url'] ) );
        }
    
        return '';
    }
    
  • Then in the shortcode template, you could simply call the my_shortcode() function above:

    echo my_shortcode( array(
        'url' => $list_item['link'],
    ), 'Visit website' );
    

But if that’s not what you meant, or if you had a shortcode in a shortcode like Caption: [myshortcode], then as said in the Shortcode API on the WordPress Codex website:

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>';
}

… your run() function (or the shortcode callback) would need to capture the second parameter passed to the function, i.e. $content as you could see above, and once you have that parameter (or its value), you can then call do_shortcode().

(With the above “caption” shortcode example, the $content is the Caption: [myshortcode].)

So for example, your run() function be written like so…

// 1. Define the $content variable.
function run( $attributes = [], $content = null ) {
    // ... your code (define $response, $layoutAttributes, $dataAttributes, etc.)

    // 2. Then do something like so:
    return $this->layout->render( $response, $layoutAttributes, $dataAttributes ) .
        do_shortcode( $content );
}

But if you need further help with that, do let me know in the comments (and preferably, please show the code in your template and explain the variables like the $response and $layoutAttributes).