Shamelessly copied from here:
https://letswp.io/add-attachment-id-to-the-class-of-wordpress-images/
add_filter( 'wp_get_attachment_image_attributes', 'add_image_id_class', 10, 2 );
function add_image_id_class( $attr, $attachment ) {
$class_attr = isset( $attr['class'] ) ? $attr['class'] : '';
$has_class = preg_match( '/wpimage\_[0-9]+/', $class_attr, $matches );
if ( !$has_class ) {
$class_attr .= sprintf( ' wpimage_%d', $attachment->ID );
$attr['class'] = ltrim( $class_attr );
}
return $attr;
}
This add a class like wpimage_{ATTACHMENT_ID}
for example wpimage_22
.
Related Posts:
- get the attachement url for the medium sized image
- Each custom image size in custom upload directory?
- How to automatically add rounded corners to thumbnails?
- Is there a simple way to just insert a link to an image (without inserting an image)?
- Watermarking Images with WordPress with WP_Image_Editor
- Get attachment/image info in JS
- Auto-modifying original [full size] images
- How to limit number of images being printer out in “Set Featured Image” pop up?
- Black and White thumbnails
- Crop image to horizontal or vertical by code based on image size
- Pasting images removes class attribute
- How can I make all gallery images to open in a new window?
- Open the attachment details modal
- Crop image without scaling or resizing with add_image_size()
- Download button for Featured Image in every post – automatically
- Can’t access ‘Store uploads in this folder’
- Is there a way to pull the first featured image in a loop and not all other featured images?
- How to Display Featured Image Title and ALT Attribute
- Is it possible to recover featured images after WordPress export/import
- how to stop generating different image sizes from parser
- Display number of images actually posted
- Confusion about arguments sent to add_image_size
- Is it possible to pull and display a single landscape oriented image
- Remove image classes from post thumbnail output
- change the $content_width
- Different image sizes for home and post pages
- Show full image thumbnail
- upload featured image in custom post type from frontend
- Make medium_large images available to insert into post
- Removing height and width from images with a caption
- Images not showing on blog
- Why does Google Image Search still display my images?
- Dynamic tagged image galleries
- Image auto resize
- WP fails to upload files to media library, /wp-admin/async-upload.php 403 forbidden
- Add a background image for Custom Post Type archives page
- Empty alt/title form check in media library
- Images stopped loadding after adding SSl
- Background-image not showing? [closed]
- GoDaddy Number of Image Files Per Directory Exceeded
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Scaling an image in a WordPress post
- add_image_size wont work after get_intermediate_image_sizes
- Ways to show multiple, separate galleries per post?
- Stop WordPress from cropping images using url parameters
- How to get the image-URL from Media-Upload in a post?
- How to get the Gallery form/section just like in Gutenberg block?
- One of my image sizes isn’t showing up in srcset
- Conflict with single and double quotes
- Featured Image Cetegory Not Shown In WordPress
- How do I get a smaller size of an avatar image
- When the new post which has no image published, save the specific image as the featured image ( by category )
- download link for uploaded images for wordpress
- How do I link a featured photo to it’s post?
- Force default OG:Image – Yoast SEO [closed]
- after migration, newly uploaded images won’t show up
- Why do I have blury images in WordPress
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- How to get the title of the random images from media library?
- How to indent pictures on WordPress blog? [closed]
- How To Display Author Photo In WordPress without any plugin?
- Allow users to upload multiple images to their profile
- how to change format jpg to webp?
- User uploads image as “Featured Image” but WordPress resizes it?
- Implementing a modal(lightbox) for all images in all post-gallery posts
- Hide Title tag on image Hover
- How to increase media image scale limit?
- Force WordPress to always generate a thumbnail for original image
- How to get the best resolution of image from srcset
- File upload size limit in wordpress and php.ini limit
- How to add php to theme to show alt attributes
- Display Title/Description/Caption of custom images on homepage
- Blank image thumbnails in media library
- Getting extra image links in code with wp_get_attachment_image
- featured image in custom poste type (backend)
- After reinstalling wordpress images do not appear in posts?
- Dinamically modifying attributes of images on posts
- Run command to optimize images after they get uploaded to WordPress
- How decrease the size of images which are present in uploads folder?
- Large size is not honoured when inserting image
- Issue uploading images
- How can I use images that are on the server locally?
- Image filter works on attachement pages but not posts. I can’t get the image ID
- The most of the images don’t appear, although URLs are correct
- Add two images with Sweet Testimonials
- Get images uploaded to this post in popup on editor screen
- Remove “align” attribute on images
- WordPress Images | How to get the cropped image?
- Import existing image as a single post
- How do I add a nested conditional within an echo – to use a default image if there isn’t one in the post?
- How do I change a Themes Header Image?
- Some images 404
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- How can I put pictures next to each other and how can I add a location? [closed]
- How to show file size of featured image? [duplicate]
- I am having trouble displaying an image at the top of a widget area [closed]
- Can’t upload svg files in WordPress
- Images uploaded in customized gallery do not link to media
- WordPress Site Broken and it gives Headers Already sent error