Skip to content

Commit cdb15e3

Browse files
committed
Media: Add filter for post thumbnail id.
Introduces new filter `post_thumbnail_id` which allows overriding the default id returned from `get_post_thumbnail_id()`. Props engelen, alexvorn2, gilbitron, sebastianpisula, SergeyBiryukov, leogermani, rzen, joemcgill, audrasjb. Fixes #23983. git-svn-id: https://develop.svn.wordpress.org/trunk@52028 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ff0425a commit cdb15e3

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ function get_post_thumbnail_id( $post = null ) {
5757
return false;
5858
}
5959

60-
return (int) get_post_meta( $post->ID, '_thumbnail_id', true );
60+
$thumbnail_id = (int) get_post_meta( $post->ID, '_thumbnail_id', true );
61+
62+
/**
63+
* Filters post thumbnail ID.
64+
*
65+
* @since 5.9.0
66+
*
67+
* @param int|false $thumbnail_id Post thumbnail ID or false if the post does not exist.
68+
* @param int|WP_Post|null $post Post ID or WP_Post object. Default is global `$post`.
69+
*/
70+
return (int) apply_filters( 'post_thumbnail_id', $thumbnail_id, $post );
6171
}
6272

6373
/**

0 commit comments

Comments
 (0)