Retrieve the format slug for a post
$postint|WP_Post|nulloptional
Default:null
This will usually be called in the the loop, but can be used anywhere if a post ID is provided.
The set of currently defined formats are:
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:
$format = get_post_format() ? : 'standard'; 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 );
}
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_format