Skip to content

Instantly share code, notes, and snippets.



Last active Jan 4, 2016
What would you like to do?
Add Attachment ID as class on images
* Attachment ID on Images
* @author Bill Erickson
* @link
function be_attachment_id_on_images( $attr, $attachment ) {
if( !strpos( $attr['class'], 'wp-image-' . $attachment->ID ) )
$attr['class'] .= ' wp-image-' . $attachment->ID;
return $attr;
add_filter( 'wp_get_attachment_image_attributes', 'be_attachment_id_on_images', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.