W3cubDocs

/WordPress

get_post_format( int|object|null $post = null )

Retrieve the format slug for a post

Description

Parameters

$post

(int|object|null) (Optional) Post ID or post object. Optional, default is the current post from the loop.

Default value: null

Return

(string|false) The format if successful. False otherwise.

Source

File: wp-includes/post-formats.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 );
}

Changelog

Version Description
3.1.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_post_format