get_post_format

The timeline below displays how wordpress function get_post_format has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.6

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to the current post in the loop.
 * @return string|false The format if successful. False otherwise.
 */
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);
}

WordPress Version: 5.5

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|object|null $post Optional. Post ID or post object. Defaults to the current post in the loop.
 * @return string|false The format if successful. False otherwise.
 */
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);
}

WordPress Version: 5.1

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop.
 * @return string|false The format if successful. False otherwise.
 */
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);
}

WordPress Version: 4.3

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop.
 * @return string|false The format if successful. False otherwise.
 */
function get_post_format($post = null)
{
    if (!$post = get_post($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);
}

WordPress Version: 4.2

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|object $post Post ID or post object. Optional, default is the current post from the loop.
 * @return mixed The format if successful. False otherwise.
 */
function get_post_format($post = null)
{
    if (!$post = get_post($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);
}

WordPress Version: 3.7

/**
 * Post format functions.
 *
 * @package WordPress
 * @subpackage Post
 */
/**
 * Retrieve the format slug for a post
 *
 * @since 3.1.0
 *
 * @param int|object $post Post ID or post object. Optional, default is the current post from the loop.
 * @return mixed The format if successful. False otherwise.
 */
function get_post_format($post = null)
{
    if (!$post = get_post($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 = array_shift($_format);
    return str_replace('post-format-', '', $format->slug);
}