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

How to use post_thumbnail_size filter in WordPress

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

post_thumbnail_size filter

Filters the post thumbnail size.

apply_filters( 'post_thumbnail_size', string|int[] $size, int $post_id )

Description

This is filter hook , its filter the the post thumbnail size.
Its consists of two parameters, one is $size and second is Post Id.

It is used in get_the_post_thumbnail() to get post thumbnail.

Parameters

  • $size : (string|int[]) Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
  • $post_id : (int) The post ID.

Live Example

To run the hook, copy the example below.

$size = apply_filters( 'post_thumbnail_size', $size ,$post); 
                         
if ( !empty( $size ) ) { 
                         
   // everything has led up to this point... 
                         
} 

  

The following example is for adding a hook callback.

// define the post_thumbnail_size callback 
function filter_post_thumbnail_size( $size , $post) { 
    // make filter magic happen here... 
    return $size; 
}; 
         
// add the filter 
add_filter( 'post_thumbnail_size', 'filter_post_thumbnail_size', 10, 1 ); 
Sandeep Kumar Mishra

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.