get_post_format

Retrieve the format slug for a post.

Description

(string|false) get_post_format( (null) $post = null ); 

Returns (string|false)

The format if successful. False otherwise.

Parameters (1)

0. $post — Optional. (null) => null
Post ID or post object. Optional, default is the current post from the loop.

Usage

  1. if ( !function_exists( 'get_post_format' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-formats.php'; 
  3.  
  4. // Post ID or post object. Optional, default is the current post from the loop. 
  5. $post = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_post_format($post); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-formats.php  
  1. function get_post_format( $post = null ) { 
  2. if ( ! $post = get_post( $post ) ) 
  3. return false; 
  4.  
  5. if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) 
  6. return false; 
  7.  
  8. $_format = get_the_terms( $post->ID, 'post_format' ); 
  9.  
  10. if ( empty( $_format ) ) 
  11. return false; 
  12.  
  13. $format = reset( $_format ); 
  14.  
  15. return str_replace('post-format-', '', $format->slug );