I have a plugin that need to remove the post thumbnail under certain conditions. Tried to hook to "get_post_metadata" filter but the code doesn't seem to work.

Here's my code:

public function helper() {
    add_filter('get_post_metadata', array($this, 'removeThumbnail'), 999, 4);

public function removeThumbnail($metadata, $object_id, $meta_key, $single) {
    return ( isset($meta_key) && '_thumbnail_id' === $meta_key ) ? false : $metadata;

My class is initialized on the_content hook.

However, it doesn't remove the featured image in the post. Any insights and ideas how to make it happen?

  • What does doesn't work mean???? Please file an edit and PROPELY explain what your exact issue is. May 6 '16 at 10:35
  • Sorry for not being clear enough. It doesn't remove the featured image in the post.
    – Gadzhev
    May 6 '16 at 10:37
  • Are you getting error, how are you initialising your class, etc etc. I again ask, file an edit with all of this info. Important info must be inside your question, and not in a comment May 6 '16 at 10:40

I found where the problem was. The code was attached to the the_content hook which runs after the thumbnail is generated.

Attached the code to post_thumbnail_html and it works now.

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.