function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
The p tags come from wpautop
Related Posts:
- Adding HTML within an image title attribute
- alt, title tags not showing
- Why html tags are being appended to my pictures?
- How to resolve – IE 6 ignores img “width” properties
- Trying to create a mouseover effect in html using Gutenberg editor
- How can I insert an image map into a WordPress blog post?
- Images will not display, when I call them up with html in wordpress, just two blank small spaces [closed]
- How to fix “.webp” being auto-added to the end of image urls
- Changing default img html markup but not in admin back-end?
- Modifying the HTML Output of Inserted Images
- Rewrite inline image markup
- Can’t add image to site via php
- What exactly is the description field when uploading an image?
- HTML Img with data:image src gets sanitized in admin?
- Landing Page with HTML CSS JS and Images on wordpress
- How to link to img src using HTML email template in WordPress
- Relative path not working at all in WAMP local environment
- Display ajax preloader for large images within posts
- Garbled HTML pulled for page description “caption id=attachment…”
- Imagem resolution responsive
- Forcing absolute src links in the RSS feed
- where is images/image.jpg?
- Issues with the excerpt (wordcount/HTML/images)
- Parallax image problem
- Hover images and Videos
- Placing a background image with text over it
- Gutenberg block HTML image rendering override
- Remove images (files) that were generated when using add_image_size()
- Displaying images from external RSS feeds?
- Why should I use “Organize my uploads into month- and year-based folders” option? (Cons/Pros)
- Which action hook can I use when a featured image has been selected
- Displaying images with relative paths in the editor
- Prevent image upload unless exact size
- Fixing external image urls
- Associate an existing image with a post
- Need help building a filter to edit the output of “image_send_to_editor”
- Image resize with image url
- Preview Image Path in Admin Section
- The WordPress Gallery, Grabbing The Link and Images?
- How to wrap every image in a post with a div?
- Featured Images on Front Page
- Display different header images based on current page
- How to upload images from my directory into my wordpress?
- Ability to edit image via WYSIWYG
- Why images/photos after being uploaded to my wordpress site get slightly blurry?
- hardcrop images in gutenberg “latest posts” block
- Use Gravatar as fallback image if no local image is not found
- add the post as canonical for attachment page wordpress
- How to get image ID to use inside wp_read_image_metadata()?
- Retrieving an alt tag from a custom field
- Exclude featured image from gallery in wp-admin
- Customizing the attachement page to show rest of all images in a gallery from post
- Disable all resizing and compression
- Is it possible to change ‘Link to’ in all images in all articles?
- Importing images results to wrong folder structure
- WP keeps looking up post thumbnail on https even though wp-config says http
- How to post a mosaic of an image gallery instead of the entire gallery inside a post’ [closed]
- using media_sideload_image with a file from theme directory
- wp_get_attachment_image_src() returning incorrect width and height [duplicate]
- Upload image without media-upload [duplicate]
- Tinymce and uploading local pictures
- Time Based change of image
- WordPress shows my picture in admin bar
- Using jQuery to automatically add class only to gif images in WordPress database [closed]
- Modify RSS – remove image and add text
- WordPress Image Scaling Quality
- Create a post from every image in my media gallery
- Retrieve Image Attachments Getting Post Thumbnail Image First
- Is there a wordpress filter to edit the markup of inline images?
- Alt text not showing up
- Removing Images from a WordPress Post
- Random Image Script Working but Want to Avoid Duplicates
- Can’t find image to remove
- How to add a custom class to all the images for a page only?
- How to link image in WordPress – Elementor when certain element does not offer that option?
- How can i place featured image after h2
- Custom image size not displaying with wp_get_attachment_image()
- Images getting smashed
- unsharp thumbnails after uploading image
- How to delete original image file after upload and resize
- Wrap post images with a link, not figure (image_send_to_editor doesn’t work)
- An error has occurred during the upload process in wordpress 5.3.2
- Access html element in media modal with jQuery
- Jetpack Lazy load images fade in
- add alt text to images loaded from json with media_sideload_image
- How to make image uploads default to full size?
- WordPress images programatically display error
- Image is missing on site homepage
- Put image onto header
- Display images in template file
- Changing image size displayed in wordpress twenty fourteen theme
- Only User Upload image Http Error
- See the all uploaded images of a user as an admin
- Broken Media Library
- Define Folder to save Images
- adding images to wordpress pagination?
- Custom filename when pasting an image from clipboard
- WordPress Bootstrap dynamic carousel showing images separately not as carousel
- How to display image ALT under image?
- Faster image upload on mobile [closed]