mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
Media: Add new functions, get_the_post_thumbnail_url() and the_post_thumbnail_url().
Adds unit tests. Props dipesh.kakadiya, swissspidy, atomicjack. Fixes #33070. git-svn-id: https://develop.svn.wordpress.org/trunk@34373 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -170,3 +170,30 @@ function get_the_post_thumbnail( $post = null, $size = 'post-thumbnail', $attr =
|
||||
*/
|
||||
return apply_filters( 'post_thumbnail_html', $html, $post->ID, $post_thumbnail_id, $size, $attr );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the post thumbnail URL.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
|
||||
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat
|
||||
* array of height and width dimensions. Default 'post-thumbnail'.
|
||||
* @return string Post thumbnail URL or empty string.
|
||||
*/
|
||||
function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
|
||||
$image = wp_get_attachment_image_url( get_post_thumbnail_id( $post ), $size );
|
||||
return isset( $image ) ? $image : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the post thumbnail URL.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat
|
||||
* array of height and width dimensions. Default 'post-thumbnail'.
|
||||
*/
|
||||
function the_post_thumbnail_url( $size = 'post-thumbnail' ) {
|
||||
echo get_the_post_thumbnail_url( null, $size );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user