I wish to remove the image classes generated by default in the output whenever post_thumbnail() is called -

<img width="1024" height="768" src="http://example.com/wp-content/uploads/2013/01/example-1024x768.jpg" class="attachment-large wp-post-image" alt="Yet another example">

I've read a bit about the remove_action() filter and this seems the way to go but I'm not sure how to use it.

  • this is untested. but what would happen if you did the_post_thumbnail(array('class' => '')); – Jamie Jan 17 '13 at 16:46
  • Thanks, tried it out but didn't work. If nothing is set it seems to default to "attachment-xlarge wp-post-image" – Staffan Estberg Jan 17 '13 at 17:05

You might try something like this in your functions.php:

//remove class from the_post_thumbnail
function the_post_thumbnail_remove_class($output) {
        $output = preg_replace('/class=".*?"/', '', $output);
        return $output;
add_filter('post_thumbnail_html', 'the_post_thumbnail_remove_class');
|improve this answer|||||
  • Applying this the image is not output. Maybe there's just a typo somewhere? – Staffan Estberg Jan 17 '13 at 17:07
  • there was a syntax issue with the preg_replace I changed the code accordingly. Here's the source of the code. – NW Tech Jan 17 '13 at 17:23

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.