has_post_format

Advertisement

Summery Summery

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

Syntax Syntax

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

Parameters Parameters

$format

(Optional) The format or formats to check.

Default value: array()

$post

(Optional) The post to check. If not supplied, defaults to the current post if used in the loop.

Default value: null

Return Return

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

Source Source

File: wp-includes/post-formats.php

 */
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 );

Advertisement

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Advertisement

Leave a Reply