Title: Image alignleft
Last modified: August 21, 2016

---

# Image alignleft

 *  [terryrook](https://wordpress.org/support/users/terryrook/)
 * (@terryrook)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/image-alignleft/)
 * I am trying to float an image to the left and wrap some text around the image
   so the text is horizontally aligned with the image. Now this is easily achieved
   with giving the image a class of: alignleft
 * The image is then placed in a paragraph along with the first line of text which
   becomes an issue when viewing on smaller devices as I then want the text not 
   to wrap including the first line. I have the following media query:
 *     ```
       img.alignleft {
       	float:none !important;
       	margin-right:0;
       }
       ```
   
 * This works great for all the text apart from the first line as it sits in the
   same paragraph as the image. The obvious solution is to wrap a div around the
   image so it removes the paragraph but as I want my client to be able to achieve
   this I am stuck as I have to add the div using code which is too tricky for the
   client.
 * Any thoughts would really be appreciated?

Viewing 1 replies (of 1 total)

 *  Thread Starter [terryrook](https://wordpress.org/support/users/terryrook/)
 * (@terryrook)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/image-alignleft/#post-4667296)
 * I found this fix thanks to Suzanne Ahjira: [](http://ahjira.com/stop-wordpress-from-wrapping-images-in-p-tags/)
 * Add this to the functions page. Then images are wrapped in a div not a paragraph:
 *     ```
       //Wraps images in div not a paragraph
       function filter_ptags_on_images($content) {
         return preg_replace('/<p[^>]*>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\/p>/', '<div class="image">$1</div>', $content);
       }
       add_filter('the_content', 'filter_ptags_on_images');
       //End of Wraps images in div not a paragraph
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Image alignleft’ is closed to new replies.

## Tags

 * [align](https://wordpress.org/support/topic-tag/align/)
 * [image](https://wordpress.org/support/topic-tag/image/)
 * [left](https://wordpress.org/support/topic-tag/left/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [terryrook](https://wordpress.org/support/users/terryrook/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/image-alignleft/#post-4667296)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
