admin管理员组文章数量:1415111
My plugin provide shortcodes like this:
[cfgeo return="city"]
- returns city name
[cfgeo include="us"]Text only seen in the US country[/cfgeo]
- returns this text only from the visitors in the US.
If I place shortcodes in the content like this:
<div>[cfgeo return="city"]</div>
<div>[cfgeo include="us"]Text only seen in the US country[/cfgeo]</div>
WordPress made error and parse it like this:
<div>[cfgeo return="city"]</div><div>[cfgeo include="us"]Text only seen in the US country[/cfgeo]<div>
That mean all between first chortcode and closed state of the shortcodes are parsed like one big shortcode.
[cfgeo return="city"]EVERYTHING INSIDE[/cfgeo]
And that made a error.
How and do I can avoid this?
My plugin provide shortcodes like this:
[cfgeo return="city"]
- returns city name
[cfgeo include="us"]Text only seen in the US country[/cfgeo]
- returns this text only from the visitors in the US.
If I place shortcodes in the content like this:
<div>[cfgeo return="city"]</div>
<div>[cfgeo include="us"]Text only seen in the US country[/cfgeo]</div>
WordPress made error and parse it like this:
<div>[cfgeo return="city"]</div><div>[cfgeo include="us"]Text only seen in the US country[/cfgeo]<div>
That mean all between first chortcode and closed state of the shortcodes are parsed like one big shortcode.
[cfgeo return="city"]EVERYTHING INSIDE[/cfgeo]
And that made a error.
How and do I can avoid this?
Share Improve this question asked Aug 23, 2019 at 10:39 Ivijan Stefan StipićIvijan Stefan Stipić 4553 silver badges16 bronze badges 3 |1 Answer
Reset to default 1When you define your shortcode, you might try one of a couple "if" statements to fix this issue, until you have time to create separate shortcodes.
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' );
I would also recommend ... when you create your replacement shortcodes, you should not only create separate codes, you should also avoid parameters with keywords like "return" and "include" for their respective names.
Good luck! Hope this was helpful.
本文标签: plugin developmentShortcode conflicts
版权声明:本文标题:plugin development - Shortcode conflicts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745220402a2648369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
[/cfgeo]
is supposed to close. It's too ambiguous. Even if it did work, it's a bad idea. Trying to have a single shortcode that does everything is poor shortcode design. – Jacob Peattie Commented Aug 23, 2019 at 12:42