WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working with post formats, most of my code looks similar to this:

if ( has_post_format( 'standard' )) {
  echo '<?php get_sidebar(); ?>';
if ( has_post_format( 'aside' )) {
  echo 'this is an aside';
if ( has_post_format( 'chat' )) {
  echo 'this is the video format';

But I also want one of the if statements to include how to call it if the user did not select a post format. Anybody know?

share|improve this question
up vote 3 down vote accepted

use get_post_format:

$format = get_post_format();
if ( false === $format )
    echo "no post format";

EDIT - an example using a switch statement:

$format = get_post_format();
switch( $format ){
    case "aside":
        echo "aside";
    case "chat":
        echo "chat";
        echo "standard";
share|improve this answer
Ooh... you were quicker on the draw! ;) – Rev. Voodoo Jun 30 '11 at 15:53
Thanks for the help! Is there a way to integrate this into my current statement? – Lucas Jun 30 '11 at 15:58
@Lucas - see my edit above. – Milo Jun 30 '11 at 16:15
I just realized this isn't working properly. It pulls the excerpt up for all post formats even if it's only supposed to pull it up if there is no post format. – Lucas Jun 30 '11 at 16:29
I'd have to see it in context. note that "standard" isn't a format. you'll see it in the UI when none is selected, but get_post_format will return false for "standard". – Milo Jun 30 '11 at 16:34

If they don't assign a format, it gets standard I think, for css purposes?

<?php $format = get_post_format(); 
if ( false === $format ) 
    $format = 'standard'; 
    get_template_part( 'format', $format ); ?>

Is some of the if logic I use, checking for format to return false for conditionals

share|improve this answer
Thanks for the help! – Lucas Jun 30 '11 at 15:58

Your Answer


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.