get_the_post_thumbnail_url

函数
get_the_post_thumbnail_url ( $post = null, $size = 'post-thumbnail' )
参数
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`.
    Required:
    Default: null
  • (string|int[]) $size Optional. Registered image size to retrieve the source for or a flat array of height and width dimensions. Default 'post-thumbnail'.
    Required:
    Default: 'post-thumbnail'
返回值
  • (string|false) Post thumbnail URL or false if no image is available. If `$size` does not match any registered image size, the original image URL will be returned.
定义位置
相关方法
the_post_thumbnail_urlget_the_post_thumbnailthe_post_thumbnailget_the_post_thumbnail_captionget_post_thumbnail_id
引入
4.4.0
弃用
-

get_the_post_thumbnail_url: 该函数返回当前文章或作为参数传递给它的文章的缩略图或特色图片的URL。

返回文章缩略图的URL。

function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
	$post_thumbnail_id = get_post_thumbnail_id( $post );

	if ( ! $post_thumbnail_id ) {
		return false;
	}

	$thumbnail_url = wp_get_attachment_image_url( $post_thumbnail_id, $size );

	/**
	 * Filters the post thumbnail URL.
	 *
	 * @since 5.9.0
	 *
	 * @param string|false     $thumbnail_url Post thumbnail URL or false if the post does not exist.
	 * @param int|WP_Post|null $post          Post ID or WP_Post object. Default is global `$post`.
	 * @param string|int[]     $size          Registered image size to retrieve the source for or a flat array
	 *                                        of height and width dimensions. Default 'post-thumbnail'.
	 */
	return apply_filters( 'post_thumbnail_url', $thumbnail_url, $post, $size );
}

常见问题

FAQs
查看更多 >