has_post_format()

You are here:

has_post_format( string|array $format = array()WP_Post|int|null $post = null )

Check if a post has any of the given formats, or any format.

Parameters Parameters

$format

(string|array) (Optional) The format or formats to check.

Default value: array()

$post

(WP_Post|int|null) (Optional) The post to check. Defaults to the current post in the loop.

Default value: null


Top ↑

Return Return

(bool) True if the post has any of the given formats (or any format, if no format specified), false otherwise.


Top ↑

More Information More Information

Usage:
1
$format = has_post_format($format, $post_id);

Top ↑

Source Source

File: wp-includes/post-formats.php

49
50
51
52
53
54
55
56
57
58
59
function has_post_format( $format = array(), $post = null ) {
    $prefixed = array();
 
    if ( $format ) {
        foreach ( (array) $format as $single ) {
            $prefixed[] = 'post-format-' . sanitize_key( $single );
        }
    }
 
    return has_term( $prefixed, 'post_format', $post );
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.
Was this article helpful?
Dislike 0
Views: 6