I’ve distilled this example down to its most basic functionality on my local site and it still has no effect, no matter which attribute I choose to change.

Here is the developer page for the filter, with a couple of examples. There’s also a working example inside functions.php in the TwentySixteen theme. I’ve read a few examples on this stack as well, and by all accounts this should work but it just doesn’t change the attribute:

function developing_filter_img_attr( $attr ) {

    $attr['class'] = "none";

    return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'developing_filter_img_attr' );

Am I missing something? Is it a priority issue? I have a few other filters within my functions file, all dealing with images and their attributes, and they’ve all worked correctly and continue to work correctly. They include:

  • intermediate_image_sizes_advanced
  • max_srcset_image_width
  • wp_calculate_image_sizes

1 Answer
1

Okay, the problem was in my interpretation of the filter. I was under the impression that this filter could be used for all images in a post, as they’re all considered attachments in the db (post type – attachment), but it’s actually reserved for the Featured Image/Post Thumbnail. Nowhere in the examples I looked through was this explicitly mentioned…

My mistake, but I wish the info online was more clear about this and the name of the filter had something to do with post_thumbnail or featured image.

Leave a Reply

Your email address will not be published. Required fields are marked *