Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use post_thumbnail_id filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 7, 2022
5 minutes read

post_thumbnail_id filter

Filters the post thumbnail ID.

apply_filters( 'post_thumbnail_id', int|false $thumbnail_id, int|WP_Post|null $post )


This is filter hook , its filter the post thumbnail ID.
Its consists of two parameters, ome is thumbnail ID or false , if post not exists and second is Post Id or WP_Post object.

It is used in get_post_thumbnail_id() which retrieves the thumbnail id.


  • $thumbnail_id : (int|false) Post thumbnail ID or false if the post does not exist.
  • $post : (int|WP_Post|null) Post ID or WP_Post object. Default is global $post.

Live Example

To run the hook, copy the example below.

apply_filters( 'post_thumbnail_html', string $html, int $post_id, int $post_thumbnail_id, string|int[] $size, string|array $attr )

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.