Title: has_post_format
Published: April 25, 2014
Last modified: February 24, 2026

---

# has_post_format( string|string[] $format = array(), WP_Post|int|null $post = null ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#wp--skip-link--target)

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

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#parameters)󠁿

 `$format`string|string[]optional

The format or formats to check.

Default:`array()`

`$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)|int
|nulloptional

The post to check. Defaults to the current post in the loop.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#return)󠁿

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

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#more-information)󠁿

##### 󠀁[Usage:](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#usage)󠁿

    ```php
    $format = has_post_format($format, $post_id);
    ```

## 󠀁[Source](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#source)󠁿

    ```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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post-formats.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post-formats.php#L49)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-formats.php#L49-L59)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#related)󠁿

| Uses | Description | 
| [has_term()](https://developer.wordpress.org/reference/functions/has_term/)`wp-includes/category-template.php` |

Checks if the current post has any of given terms.

  | 
| [sanitize_key()](https://developer.wordpress.org/reference/functions/sanitize_key/)`wp-includes/formatting.php` |

Sanitizes a string key.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/has_post_format/?output_format=md#comment-content-3845)
 2.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/has_post_format/#comment-3845)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_post_format%2F%23comment-3845)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_post_format%2F%23comment-3845)
 4. Example migrated from Codex:
 5.     ```php
        <?php
        /*
         * Do something if the post format is a gallery
         */
    
        if ( has_post_format('gallery') ) {
          // Do something
        }
        ?>
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_post_format%2F%3Freplytocom%3D3845%23feedback-editor-3845)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fhas_post_format%2F)
before being able to contribute a note or feedback.