In opposite to get_post_format, the conditional has_post_format() function returns a boolean value and should be the perfect function for a conditional check like:

if ( has_post_format( array( 'gallery', 'image' ) ) {
    // I'm a gallery or image format post; do something
}

(see this answer)

Unfortunately, has_post_format() is not sufficient to check for the standard post format. So how would I achieve something like:

if ( has_post_format( 'standard' ) {
    // I'm a standard format post
}

1 Answer
1

To do that, one needs to go back to get_post_format() as the Codex page explains:

$format = get_post_format();
if ( false === $format )
    $format="standard";

So in order to check if a post is in standard format, I can use this shortcut:

if ( false == get_post_format() ) {
    // I'm a standard format post
}
/* or */
if ( ! get_post_format() ) {
    // I'm a standard format post
}

Or reverse the scheme to check if a post is just not in standard format:

if ( false !== get_post_format() ) {
    // I'm everything but a standard format post
}
/* or */
if ( get_post_format() ) {
    // I'm everything but a standard format post
}

Leave a Reply

Your email address will not be published. Required fields are marked *