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.
[/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