Support » Fixing WordPress » How to use wp_post_thumbnail_class_filter

  • Resolved humanitas

    (@humanitas)


    I would like to remove the class attribute from the post image thumbnail. It currently gets printed as:

    class=" wp-post-image"

    I would like to eradicate it entirely! Or, if not possible, then to replace it with:

    class=""

    I have studied the filter int he source code and tried to use it as set out below. However, it fails to work. Unfortunately there is no reference to the use of this filter on these forums or on Google. Is it possible to suggest an amendment or correction to my attempt?
    Many thanks.

    `function my_wp_post_thumbnail_class_filter_remove( $class ) {
    $attr[‘class’] .= ”;
    return $attr;

    add_filter( ‘wp_get_attachment_image_attributes’, ‘my_wp_post_thumbnail_class_filter’ );
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    try it with this in your theme’s functions.php:

    add_filter( 'post_thumbnail_html', 'remove_thumbnail_class', 10 );
    function remove_thumbnail_class( $html ) {
    	$html = preg_replace( '/class="(.*?)"/', '', $html );
        return $html;
    }

    Many thanks! That works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use wp_post_thumbnail_class_filter’ is closed to new replies.