Trying to add an img class = "the image alt field" to the images in a native wordpress gallery so i can use jquery isotope to filter the gallery. I could use the image alt field or the description field to give the image a simple class of "apple" or "orange" or "apple tasty". This should probably be done using tags somehow but surprising that is not a feature of wordpress.
add_filter('wp_get_attachment_link', 'galleryWIthClass');
function galleryWithClass($src) {
global $post;
$alt= get_post_meta($id, '_wp_attachment_image_alt', true);
echo str_replace('<img', '<img class="'. $alt.'" ', $src);
}
This code results in : img class = "".
I need to set $id = "something" in order to return some sort of value.
I feel im approaching this wrong.
Any advice?
wp_get_attachment_image_attributes
would be a more appropriate filter.