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

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

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);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.