在变量字符串中添加函数

Add Function Within Variable String

我正在尝试在字符串中添加一个函数以通过短代码显示函数的输出,但它显示错误。

function foo_shortcode($atts, $content = null) { 

$datashortcode = '<div>'

.if(function_exists('rtb_kk'))
{
    rtb_kk();
}. 
'</div>'
;

return $datashortcode; 
}

add_shortcode('showfoo', 'foo_shortcode');

我哪里弄错了?

你有语法错误,

$datashortcode = '<div>'.(function_exists('rtb_kk') ? rtb_kk() : '').'</div>';

替换此行。