Can I get a DIV auto inserted around IMG instead of P (5 posts)

  1. johnasp
    Posted 7 years ago #

    I find the fact that WP auto wraps a P tag around all my IMG tags and its' very annoying. The <p> forces a line break above the image and ruins the looks of my pages.

    Can I get WP to auto wrap a DIV around the IMG instead?

    PS - I'm using WP as a CMS and asking users to add the DIV themselves simply is not an option.

  2. namelessfaceless
    Posted 6 years ago #

    I'm having the exact same problem...did you manage to solve this??

  3. doc4
    Posted 6 years ago #


    Are you inserting the images directly into the TinyMCE Editor? Removal of the <p> tag will also affect the paragraphs themselves. What you want to do is create a custom field and ask the user to type in the name of the image file. Something such as: myImage.jpg then add the proper div coding to your theme files. Here is an example:

    <?php if( get_post_meta($post->ID, 'customFieldName', true) ) { ?>
     <div class="image">
      <img src="<?php bloginfo('url'); ?>/wp-content/uploads/<?php echo get_post_meta($post->ID, 'customFieldName', $single=true) ?>">
    <?php } ?>

    The above code allows for the possibility that an image might not exist because we are checking for the image prior to publishing the code.

  4. FunnyBunnyHelena
    Posted 6 years ago #

    I also want to know how to solve this. I want to be able to put two or more images on same line, but centered. hmm.

    I am using media library to insert images btw. And latest wordpress. :)

  5. Scoe
    Posted 6 years ago #

    I would also like to know. I don't really want to ask a client to insert <div> tags everytime they want a specific image. e.g. a banner

Topic Closed

This topic has been closed to new replies.

About this Topic