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 ); 
JOIN 100,000+ SUBSCRIBER's FAMILY

 Subscribe to our weekly newsletter below and never miss the latest updates in WordPress