【问题标题】:Add Function Within Variable String在变量字符串中添加函数
【发布时间】:2023-03-28 12:05:01
【问题描述】:

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

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

$datashortcode = '<div>'

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

return $datashortcode; 
}

add_shortcode('showfoo', 'foo_shortcode');

我在哪里犯错了?

【问题讨论】:

  • 你根本做不到。这是语法错误。
  • 这么多语法错误,先阅读一些关于PHP的教程然后写一个插件到wordpress :)

标签: php wordpress plugins shortcode


【解决方案1】:

你有语法错误,

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

替换此行。

【讨论】:

  • 感谢您的回答,它有效,但现在它在页面顶部显示短代码内容。
  • 所以根据您的要求固定它的位置,。因为您没有在问题中显示任何 html
猜你喜欢
  • 2015-01-23
  • 2016-01-27
  • 1970-01-01
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多