Outil de recherche WordPress pour les développeurs et auteurs de thèmes



has_post_thumbnail ›

Depuis2.9.0
Dépréciéen/a
has_post_thumbnail ( $post = null )
Paramètres:
  • (int|WP_Post) $post Optional. Post ID or WP_Post object. Default is global `$post`.
    Requis: Non
    Défaut: null
Retourne:
  • (bool) Whether the post has an image attached.
Défini(e) dans:
Codex:
Changelog:
  • 4.4.0

Determines whether a post has an image attached.

For more information on this and similar theme functions, check out the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags} article in the Theme Developer Handbook.



Source

function has_post_thumbnail( $post = null ) {
	$thumbnail_id  = get_post_thumbnail_id( $post );
	$has_thumbnail = (bool) $thumbnail_id;

	/**
	 * Filters whether a post has a post thumbnail.
	 *
	 * @since 5.1.0
	 *
	 * @param bool             $has_thumbnail true if the post has a post thumbnail, otherwise false.
	 * @param int|WP_Post|null $post          Post ID or WP_Post object. Default is global `$post`.
	 * @param int|string       $thumbnail_id  Post thumbnail ID or empty string.
	 */
	return (bool) apply_filters( 'has_post_thumbnail', $has_thumbnail, $post, $thumbnail_id );
}