Strip Image Classes from HTML Output

Does anyone know how to remove all of this from the image HTML?

class="aligncenter size-full wp-image-31053"

Related posts

1 comment

  1. Take a closer look at get_image_tag() which can take a lot of parameters like $id, $alt, $title, $align, $size.

    If you look even closer you’ll find the get_image_tag_class filter to change the image class names (like class, ID, align and size).

    You can use the filter within your functions.php like this:

    Note: This will still return an empty tag like: class=""

    function strip_image_class($class, $id, $align, $size) {
        return '';
    }
    add_filter('get_image_tag_class', 'strip_image_class', 0, 4);
    

    Update: To completely remove everything related to the class you’ll have to filter the $html:

    function strip_entire_image_class($html) {
        return preg_replace('/ class="(.*)"/', '', $html);
    }
    add_filter('get_image_tag', 'strip_entire_image_class', 0, 4);
    

Comments are closed.