WordPress.org

Forums

Prevent WordPress from wrapping P tags around images (4 posts)

  1. Russell Heimlich
    Member
    Posted 7 years ago #

    Is there a plugin available to stop Worpess from wrapping my images in P tags? What is the PHP function that does this? I checked formatting.php in the 'WP-includes' folder and didn't see anything that looks familiar

  2. jabecker
    Member
    Posted 7 years ago #

    I would really like an answer to this, too. If I wanted p tags around my pictures, I'd put them there.

  3. Russell Heimlich
    Member
    Posted 7 years ago #

    This seems to be an elusive topic.

  4. tripleX2k7
    Member
    Posted 7 years ago #

    Hi

    I realise you guys have probably either figured this out or given up on it but seeing as this shows up right at the top of google results for this problem then I thought I would say how to solve it.

    As it says in the topic at http://wordpress.org/support/topic/119014?replies=6 , wordpress knows that an img tag loose outside of p tags is invalid code (although it is valid if you have a containing div tag, as most themes do). WordPress detects that you haven't got a block level element around the image, and inserts p tags around it.

    To solve this, you can put a div tag around the image, for example:
    <div><img src='image.jpg' alt='an image' /></div>.
    This will cause WordPress to leave your image alone.

Topic Closed

This topic has been closed to new replies.

About this Topic