Nested shortCode functions in the functions.php file

I’m trying to get a shortcode function (newStuff) to display inside of another function (oldStuff), but I’m running into trouble. Both shortCode functions are listed below, as well as what I’ve tried. Can someone please help me get the “newStuff” function displaying inside of the “oldStuff” function?

Thanks!

Current Functions

function newStuff(){
return '
only raw html is in this function
';
}
add_shortcode('new', 'newStuff');

function oldStuff(){
return '
only raw html is in this function
';
}
add_shortcode('old', 'oldStuff');

I tried including the short code, but it didn’t work

function oldStuff(){
return '
[new]
only raw html is in this function
';
}
add_shortcode('old', 'oldStuff');

I tried including the function, but it didn’t work

function oldStuff(){
return '
echo newStuff();
only raw html is in this function
';
}
add_shortcode('old', 'oldStuff');

1 Answer
1

You should use do_shortcode() function in both strings you are returning it will execute the shortcodes in the string.

function oldStuff(){
    return do_shortcode('
        [new]
        only raw html is in this function
    ');
}
add_shortcode('old', 'oldStuff');

Leave a Comment