get_post_format() – Retrieve the format slug for a post

You appear to be a bot. Output may be restricted

Description

Retrieve the format slug for a post

Usage

$string|false = get_post_format( $post );

Parameters

$post
( int|WP_Post|null ) optional – Optional. Post ID or post object. Defaults to the current post in the loop.

Returns

string|false The format if successful. False otherwise.

Source

File name: wordpress/wp-includes/post-formats.php
Lines:

1 to 21 of 21
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 );
}
 

 View on GitHub View on Trac