Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
}
share|improve this question
2  
possible duplicate of has_post_format() vs. get_post_format() –  Chip Bennett Nov 29 '12 at 13:01
    
Addressed in the linked answer, making this a duplicate. –  Chip Bennett Nov 29 '12 at 13:02
add comment

1 Answer

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
}
share|improve this answer
1  
Or simply use if ( get_post_format() ) or if ( ! get_post_format() ) ;) –  kaiser Nov 29 '12 at 14:04
    
@kaiser Totally, answer updated! –  glueckpress Nov 29 '12 at 17:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.