Skip to content

Instantly share code, notes, and snippets.

@billerickson
Last active January 4, 2016 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/8586220 to your computer and use it in GitHub Desktop.
Save billerickson/8586220 to your computer and use it in GitHub Desktop.
Add Attachment ID as class on images
<?php
/**
* Attachment ID on Images
*
* @author Bill Erickson
* @link http://www.billerickson.net/code/add-attachment-id-class-images/
*/
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