WordPress at a glance

get_post_format() WP 1.0

Retrieve the format slug for a post

1 time — 0. sec (speed of light) | 50000 times — 2.73 sec (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() WP 5.7.2

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

From tag: post format

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

No comments
    Log In