post_thumbnail_url filter

Filters the post thumbnail URL.

apply_filters( 'post_thumbnail_url', string|false $thumbnail_url, int|WP_Post|null $post, string|int[] $size )


This is filter hook , its filter the post thumbnail URL.
Its consists of three parameters, one is $thumbnail_url, second is Post Id or Post object and third for $size .

It is used in get_the_post_thumbnail() which returns post thumbnail URL.


  • $thumbnail_url : (string|false) Post thumbnail URL or false if the post does not exist.
  • $post : (int|WP_Post|null) Post ID or WP_Post object. Default is global $post.
  • $size : (string|int[]) Registered image size to retrieve the source for or a flat array of height and width dimensions. Default ‘post-thumbnail’.

Live Example

To run the hook, copy the example below.

apply_filters( 'post_thumbnail_url', string|false $thumbnail_url, int|WP_Post|null $post, string|int[] $size )

The following example is for adding a hook callback.

// define the post_thumbnail_url callback 
function filter_post_thumbnail_url( $thumbnail_url , $post, $size) { 
    // make filter magic happen here... 
    return $thumbnail_url; 
// add the filter 
add_filter( 'post_thumbnail_url', 'filter_post_thumbnail_url', 10, 1 ); 

To remove a hook callback, use the example below.

// remove the filter 
remove_filter( 'post_thumbnail_url', 'filter_post_thumbnail_url', 10, 1 ); 

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