我的插件提供了这样的短代码:
[cfgeo return="city"] -返回城市名称
[cfgeo include="us"]Text only seen in the US country[/cfgeo] --仅从美国游客那里返回此文本。
如果我在这样的内容中放置了短代码:
[cfgeo return="city"]
[cfgeo include="us"]Text only seen in the US country[/cfgeo]WordPress犯了错误,并按如下方式解析:
[cfgeo return="city"][cfgeo include="us"]Text only seen in the US country[/cfgeo]这意味着所有的第一个合唱码和关闭状态之间的短代码被解析为一个大的短代码。[cfgeo return="city"]EVERYTHING INSIDE[/cfgeo]这就犯了个错误。我怎样才能避免这种情况?发布于 2019-08-24 00:25:51
在定义短代码时,您可能会尝试一对"if“语句中的一条来解决此问题,直到您有时间创建单独的短代码为止。
function cfgeo_shortcode( $atts, $content = "" ) {
if (!isset($content) || stristr($content,'cfgeo')!==FALSE){
// do short shortcode stuff here
} else {
// do 'Container' shortcode stuff here
}
return $output;
}
add_shortcode( 'cfgeo', 'cfgeo_shortcode' );我也建议..。当您创建替换的短代码时,您不仅应该创建单独的代码,还应该避免为它们各自的名称使用“返回”和“包括”等关键字的参数。
祝好运!希望这能帮上忙。
https://wordpress.stackexchange.com/questions/345740
复制相似问题