Testing against WordPress 6.0 and using Codex, get_image_tag_class filter to remove all existing default classes and add new class img-fluid is not working

Here is the code that I am using in functions.php file

add_filter( 'get_image_tag_class', '__return_empty_string' );

function example_add_img_class( $all_the_default_classes ) {
    return $all_the_default_classes . ' img-fluid';
add_filter( 'get_image_tag_class', 'example_add_img_class' );

and I am still getting all default classes? besides the width="825" height="800" attributes. Can you please let me know how I can fix this to remove existing classes and add the new class img-fluid and render image without having width="825" height="800" attributes enter image description here

  • if you rename the $class variable to $all_the_default_classes the solution should become much clearer
    – Tom J Nowell
    Aug 1 at 16:30
  • Well, it looks more clear now but I am not sure if we can call it a solution, since still not doing the job!
    – Suffii
    Aug 1 at 17:25


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.