Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress wp-post-image class remover

Tags:

wordpress

We use the_post_thumbnails to get our images displayed.

We want to use them with a specific class called "test" but we cant manage it!

We use this code:

 <?php the_post_thumbnail('pin-photo-large', array('class' => 'test')); ?>

But the output of the image seems like this:

 class="test wp-post-image"

How can we overcome this issue and get an output like this ?

 class="test" 
like image 218
jeejee Avatar asked Jan 19 '26 12:01

jeejee


1 Answers

Update: Add this to your functions.php file:

remove_action( 'begin_fetch_post_thumbnail_html', '_wp_post_thumbnail_class_filter_add' );

Explanation: In media.php, the _wp_post_thumbnail_class_filter function adds the wp-post-image class to post thumbnails. By removing the begin_fetch_post_thumbnail_html action hook (located in default-filters.php), the function will no longer apply to the_post_thumbnail.


Old answer below:

I also searched for a proper way to filter out the wp-post-image class, alas to no avail. The only solution I figured out was to edit a (gasp!) core file: media.php and replace this:

function _wp_post_thumbnail_class_filter( $attr ) {
    $attr['class'] .= ' wp-post-image';
    return $attr;
}

by this:

function _wp_post_thumbnail_class_filter( $attr ) {
    return $attr;
}

There's certainly a better way to do this than to patch a core file, but this can be a good temporary solution.

like image 88
Daze Avatar answered Jan 22 '26 05:01

Daze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!