WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 3 down vote accepted

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');
share|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
Ah, works great now. Thanks! – Staffan Estberg Jan 17 '13 at 17:33
No problem. Glad I could help. – NW Tech Jan 17 '13 at 18:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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