1

I hope this isn't a stupid question, but I can't find an answer. I just want to display (in the loop) what post format a post is in. I'm trying to avoid using a bunch of if / else if conditions.

I'm not trying to restyle the post based on format, just display "Gallery" or "Quote" or whatever the current post format is, given they are enabled for my current theme.

5

Try:

<?php
echo get_post_format_string( get_post_format() );
?>

EDIT

Note, if you want a fail-safe output, try this:

<?php
if ( get_post_format() ) {
    echo get_post_format_string( get_post_format() );
} else {
    ehco 'Standard';
}
?>

Or, if you want to store it in a variable:

<?php
$post_format_string = ( get_post_format() ? get_post_format_string( get_post_format() ) : 'Standard' );
// echo the result
echo $post_format_string;
?>

Codex ref: get_post_format(), get_post_format_string()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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