Skip to content

Instantly share code, notes, and snippets.

@billerickson

billerickson/general.php

Last active Jan 4, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.