首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >短代码冲突

短代码冲突
EN

WordPress Development用户
提问于 2019-08-23 10:39:36
回答 1查看 123关注 0票数 0

我的插件提供了这样的短代码:

[cfgeo return="city"] -返回城市名称

[cfgeo include="us"]Text only seen in the US country[/cfgeo] --仅从美国游客那里返回此文本。

如果我在这样的内容中放置了短代码:

代码语言:javascript
复制
[cfgeo return="city"]

[cfgeo include="us"]Text only seen in the US country[/cfgeo]

WordPress犯了错误,并按如下方式解析:

代码语言:javascript
复制
[cfgeo return="city"][cfgeo include="us"]Text only seen in the US country[/cfgeo]这意味着所有的第一个合唱码和关闭状态之间的短代码被解析为一个大的短代码。[cfgeo return="city"]EVERYTHING INSIDE[/cfgeo]这就犯了个错误。我怎样才能避免这种情况?
EN

回答 1

WordPress Development用户

回答已采纳

发布于 2019-08-24 00:25:51

在定义短代码时,您可能会尝试一对"if“语句中的一条来解决此问题,直到您有时间创建单独的短代码为止。

代码语言:javascript
复制
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' );

我也建议..。当您创建替换的短代码时,您不仅应该创建单独的代码,还应该避免为它们各自的名称使用“返回”和“包括”等关键字的参数。

祝好运!希望这能帮上忙。

票数 1
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/345740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档