Support » Fixing WordPress » Can I get a DIV auto inserted around IMG instead of P

  • 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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • namelessfaceless


    I’m having the exact same problem…did you manage to solve this??




    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.



    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. 🙂

    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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Can I get a DIV auto inserted around IMG instead of P’ is closed to new replies.