WordPress.org

Ready to get started?Download WordPress

Forums

wpautop shortcode handling - inline vs block elements (3 posts)

  1. swinggraphics
    Member
    Posted 2 years ago #

    wpautop recognizes shortcode syntax and will attempt not to wrap p or br tags around shortcodes that stand alone on a line by themselves.
    http://codex.wordpress.org/Shortcode_API#Output

    Actually, if a shortcode begins a paragraph, it doesn't get a p tag.

    This annoys me greatly. I get extra p tags when they're inappropriate, and no p tags when they're necessary.

    In the case of the former, I solve it with preg_replace.

    Here is an example of the latter:

    [highlight]For more information, please contact Justin Case at 800-555-0505.[/highlight]

    [highlight] wraps the content in a span tag. When this begins a paragraph, it does not get wrapped in a p tag.

    As far as I can tell, there is no way for a shortcode to know that it starts a paragraph so I can have it add its own p tag.

    At present, not having p tags is a cosmetic problem only. My ugly solution? span + p {margin-top: .5em;}

    The desired behavior would be to apply wpautop as normal when the shortcode produces inline elements, and not to apply tags when the shortcode produces block-level elements.

    I'm not sure I have the chops to try my hand at rewriting the processor. To someone who knows about such things: Does this sound like a good idea, or is there some reason we wouldn't want to correct…err…modify the current behavior?

    After writing the above, I found this issue: http://core.trac.wordpress.org/ticket/12061. OMG this is so necessary. It would be trivial and quite desireable for shortcode authors to specify, yes, run autop on my shortcode or no, don't you dare touch it, i'll do it myself! :)

  2. acurran
    Member
    Posted 2 years ago #

  3. swinggraphics
    Member
    Posted 2 years ago #

    I am going to try this out! Off the top of my head, I don't think any of the shortcodes from the plugins I use most would be affected by this change. And if any are, I can always wrap them in my own shortcode to run them thru wpautop. Thanks!

    I still think WP should have a more elegant way of handling this in core.

Topic Closed

This topic has been closed to new replies.

About this Topic