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

Read more here: wp_get_attachment_image_attributes not working for me


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: