Skip to content

Commit ff0425a

Browse files
committed
Media: Add filter for post thumbnail url.
Introduces new filter `post_thumbnail_url` which allows overriding the default url returned from `wp_get_attachement_image_url()`. Props ibenic, SergeyBiryukov, jackreichert, audrasjb. Fixes #40547. git-svn-id: https://develop.svn.wordpress.org/trunk@52027 602fd350-edb4-49c9-b593-d223f7449a82
1 parent b7bbb52 commit ff0425a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/wp-includes/post-thumbnail-template.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,19 @@ function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
227227
return false;
228228
}
229229

230-
return wp_get_attachment_image_url( $post_thumbnail_id, $size );
230+
$thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size );
231+
232+
/**
233+
* Filters the post thumbnail URL.
234+
*
235+
* @since 5.9.0
236+
*
237+
* @param string|false $thumbnail_url Post thumbnail URL or false if the post does not exist.
238+
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`.
239+
* @param string|int[] $size Registered image size to retrieve the source for or a flat array
240+
* of height and width dimensions. Default 'post-thumbnail'.
241+
*/
242+
return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size );
231243
}
232244

233245
/**

0 commit comments

Comments
 (0)