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

---

# get_post_format( int|WP_Post|null $post = null ): string|false

## In this article

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

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

Retrieve the format slug for a post

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

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

Post ID or post object. Defaults to the current post in the loop.

Default:`null`

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

 string|false The format if successful. False otherwise.

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

This will usually be called in the [the loop](https://codex.wordpress.org/The_Loop),
but can be used anywhere if a post ID is provided.

The set of currently defined formats are:

 * aside
 * chat
 * gallery
 * link
 * image
 * quote
 * status
 * video
 * audio

Note also that the default format (i.e., a normal post) returns false, but this 
is also referred in some places as the ‘standard’ format. In some cases, developers
may wish to do something like the following to maintain consistency:

    ```php
    $format = get_post_format() ? : 'standard';
    ```

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

    ```php
    function get_post_format( $post = null ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return false;
    	}

    	if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) {
    		return false;
    	}

    	$_format = get_the_terms( $post->ID, 'post_format' );

    	if ( empty( $_format ) ) {
    		return false;
    	}

    	$format = reset( $_format );

    	return str_replace( 'post-format-', '', $format->slug );
    }
    ```

[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#L17)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post-formats.php#L17-L37)

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

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

Retrieves the terms of the taxonomy that are attached to the post.

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

Checks a post type’s support for a given feature.

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

Retrieves post data given a post ID or post object.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_post_format/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_post_format/?output_format=md#)

| Used by | Description | 
| [WP_REST_Posts_Controller::prepare_item_for_response()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/prepare_item_for_response/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Prepares a single post output for response.

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

Retrieves an embed template path in the current or parent template.

  | 
| [get_inline_data()](https://developer.wordpress.org/reference/functions/get_inline_data/)`wp-admin/includes/template.php` |

Adds hidden fields with the data for use in the inline editor for posts and pages.

  | 
| [post_format_meta_box()](https://developer.wordpress.org/reference/functions/post_format_meta_box/)`wp-admin/includes/meta-boxes.php` |

Displays post format form elements.

  | 
| [get_post_class()](https://developer.wordpress.org/reference/functions/get_post_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the post container element.

  | 
| [get_body_class()](https://developer.wordpress.org/reference/functions/get_body_class/)`wp-includes/post-template.php` |

Retrieves an array of the class names for the body element.

  | 
| [wp_xmlrpc_server::mw_getPost()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/mw_getpost/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves a post.

  | 
| [wp_xmlrpc_server::mw_getRecentPosts()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/mw_getrecentposts/)`wp-includes/class-wp-xmlrpc-server.php` |

Retrieves list of recent posts.

  | 
| [wp_xmlrpc_server::_prepare_post()](https://developer.wordpress.org/reference/classes/wp_xmlrpc_server/_prepare_post/)`wp-includes/class-wp-xmlrpc-server.php` |

Prepares post data for return in an XML-RPC object.

  | 
| [_WP_Editors::editor_settings()](https://developer.wordpress.org/reference/classes/_wp_editors/editor_settings/)`wp-includes/class-wp-editor.php` |  |

[Show 5 more](https://developer.wordpress.org/reference/functions/get_post_format/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_post_format/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_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/get_post_format/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_post_format/?output_format=md#comment-content-800)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_post_format/#comment-800)
 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%2Fget_post_format%2F%23comment-800)
    Vote results for this note: 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%2Fget_post_format%2F%23comment-800)
 4. **Usage in Templates**
 5.     ```php
        /*
         * Pull in a different sub-template, depending on the Post Format.
         * 
         * Make sure that there is a default format.php file to fall back to as a default.
         * Name templates format-link.php, format-aside.php, etc.
         *
         * You should use this in the loop.
         */
        get_template_part( 'format', get_post_format() );
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_format%2F%3Freplytocom%3D800%23feedback-editor-800)

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