Support » Everything else WordPress » Shortcode self closing bug?

  • Think I might have found a bug in the shortcode API?

    I’m using it for one of my plugins, and its possible to have both self closing tags and tags with content in the middle.

    Anyway, the bug is that code like this:

    Testing [intlink id="1" /] self close. [intlink id="2"]Testing content[/intlink]

    becomes:

    Testing <a href="">selc close. <a href="">Testing content</a></a>

    As you can see, the first opening shortcode is running until the last closing tag, even thought it is self closed.

    Having read the manual I understand the shortcode parser can’t handle nesting of the same tags, but in this case I’m not trying to nest!

    Is this a bug or am I doing something wrong?

Viewing 3 replies - 1 through 3 (of 3 total)
  • MichaelH

    (@michaelh)

    Just noting bug report you made:
    http://core.trac.wordpress.org/ticket/9264

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Shortcodes are not XHTML. They don’t support self-closing, period.

    Shortcodes either take the form of [shortcode] or [shortcode] text [/shortcode]. That’s it.

    Admittedly, the API is not clear on this point, as it does use the term “self-closing”. However, that is referring to a form of just [shortcode] being replaced by something else, similar to how the gallery shortcode operates.

    Generally speaking, any particular shortcode takes either one form or the other, but not both. This may not always be true, but it usually is.

    Thread Starter rb-cohen

    (@rb-cohen)

    Both the documentation and inline documentation mention self closing, I assumed this was a feature of the wordpress shortcode setup?

    My suggested fix is to stop the shortcode regex being too greedy. I still see this as an issue, even if using the documented self closing ‘/’ is not the answer. Perhaps we can just make the regex stop looking if it finds another opening tag instead?

    I agree that a particular shortcode should stick to one form or another, but in testing I found that [test id="1"][/test] would not work, and so had to use [test id="1"] if I wanted no content. Perhaps another bug? Or is this correct behavior?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Shortcode self closing bug?’ is closed to new replies.