Support » Fixing WordPress » [shortcodes] Paragraphs wrap shortcode markup (invalid HTML)

  • After upgrading to version 3.5, I soon noticed that both native WP shortcodes and user-defined ones, have their content wrapped by a <p></p> tag, thus invalidating most of the markup.

    The odd thing is that in my theme (self-made) I’ve specified that the wp_autop filter processing should not be applied to post and page’s contents.

    In short, the [gallery] shortcode now appears as:

    <div id=”gallery-n” class=”…”>…</div>

    which is invalid.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I think this has been going on for a while, and it causes me grief as well. It might be prudent to generate some ideas for solutions. Off the top of my head, we could:

    • Close the preceding <p> tags upon entering the shortcode, then open it again at the end
    • Recursively parse the body text from within the shortcode and check for or remove the surrounding paragraph tags
    • Add a TinyMCE plugin that detects shortcodes in the entered text and works to fix formatting on post save and retrieval

    Each of these has obvious shortcomings, but it’s all I can think of.

    Problem is that some popular theme market websites don’t allow such (necessary) preprocessing if you want to sell your themes with them. This is clearly a bug in the core WP functions (such as the autopee ones), because a p element should surround only inline elements (XHTML) or their corresponding HTML5 counterparts. This could be easily fixed if WP would allow users to control this behavior in the Settings panel.

    The TinyMCE Advanced plugin has an option for disabling the auto-insertion and removal of <p> tags, and of course developers can remove the autop hook manually if they choose – you’re suggesting that this should be a part of WP core? Not a bad idea, I wouldn’t mind having it available on one of the settings pages.

    The autop is a well-known hazard in templating communities, but that’s not to say that it isn’t inherently bad – it can save developers a lot of work when they’re trying to get their clients to fill in content.

    Should WP have a global autop enable/disable option, or are we strictly looking at the area around shortcodes?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[shortcodes] Paragraphs wrap shortcode markup (invalid HTML)’ is closed to new replies.