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?

  • You’re using the same shortcode for very different things. They should be separate. Aug 23 '19 at 10:43
  • Yes, before that was working, after 5.2 not works anymore. You are right about that but still thinking is there solution or I must add new shortcodes? Aug 23 '19 at 10:51
  • 1
    You need a separate shortcode. Even as a human it's impossible to read your examples and know which shortcode [/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. Aug 23 '19 at 12:42

When 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.

  • This is good point. It may help a lot in this case but I must separate short code. Thanks! Aug 24 '19 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.