WordPress at a glance

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/object/null)
Post ID or post object. Optional.
Default: current post from the loop

Code of get post format: wp-includes/post-formats.php VER 5.1.1

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

Related Functions

From tag: post format

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register