get_post_format() WP 1.0
Retrieve the format slug for a post
1 time = 0.s = speed of light | 50000 times = 2.73s = fast
No Hooks.
Return
String/false. The format if successful. False otherwise.
Usage
get_post_format( $post );
- $post(int/WP_Post/null)
- Post ID or post object.
Default: current post in the loop
Changelog
Since 3.1.0 | Introduced. |
Code of get_post_format() get post format WP 5.6
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 );
}Related Functions
From tag: post format
More from Template Tags: Posts, Pages, ...
- body_class()
- get_post_time()
- get_the_date()
- have_posts()
- in_the_loop()
- next_image_link()
- next_post_link()
- next_posts_link()
- post_class()
- post_password_required()
- posts_nav_link()
- previous_image_link()