函数.php文件中嵌套的短码函数

时间:2014-12-10 作者:Mr. B

我试图获得一个短代码函数(newStuff)来显示另一个函数(oldStuff)的内部,但我遇到了麻烦。下面列出了两个短代码函数,以及我尝试过的功能。有人能帮我在“oldStuff”函数中显示“newStuff”函数吗?

谢谢

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 个回复
最合适的回答,由SO网友:M-R 整理而成

您应该使用do_shortcode() 函数,它将执行字符串中的短代码。

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

结束

相关推荐

阻止在父主题中执行PHP

我已经设置了一个子主题,可以对我的网站进行自定义更改,而不会在每次更新时将其删除。一个更改是删除一个包装器,该包装器在“content hero.php”文件中显示页面标题,周围有大量空白。父文件中的代码为:<div class=\"hero <?php echo edin_additional_class(); ?>\"> <?php if ( ! is_page_template( \'page-templates/front-page.php\' ) ) : ?