WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 am working on a WordPress theme using Bones. I would like to be able to show some text just above the title of each post if the post is either featured, password protected or private.

So far I came up with the following - this is directly inserted into index.php, single.php, archive.php and search.php (not in a function in functions.php)

<?php if(is_sticky()): ?>
  <h6 class="post-format"><?php _e('Featured', 'bonestheme'); ?></h6>
<?php endif; ?>
<?php if($post->post_password): ?>
  <h6 class="post-format"><i class="icon-lock"></i> <?php _e('Protected', 'bonestheme'); ?></h6>
<?php endif; ?>
<?php if($post->post_status == 'private'): ?>
  <h6 class="post-format"><i class="icon-ban-circle"></i> <?php _e('Private', 'bonestheme'); ?></h6>
<?php endif; ?>

The code above works fine, however, I would like to improve it and put it a function in functions.php. So far I have come up wit the following.

function print_post_format(){

  printf( __( '<h6 class="post-format">%s</h6>', 'bonestheme' ), 'Featured' );

  printf( __( '<h6 class="post-format"><i class="icon-lock"></i>%s</h6>', 'bonestheme' ), 'Protected' );

else($post->post_status == 'private'):
  printf( __( '<h6 class="post-format"><i class="icon-ban-circle"></i>%s</h6>', 'bonestheme' ), 'Private' );


When calling this function, 'Featured' shows up, however, 'Protected' and 'Private' do not. Any help would be greatly appreciated.

Thank you, Ian

share|improve this question
Does it work if you add global $post; above your first if-statement? Just below your function print_post_format(){. – hampusn Sep 20 '12 at 10:51
Thanks for your reply. Yes, that solves most of the problem - However, I think I have an issue in my 'if'/'else' statement - If I let the whole chunk of code run, I get the following error 'Parse error: syntax error, unexpected '(', expecting ':' in C:\...\functions.php on line 340' - line 340 being the first 'else' statement. – Ian Muscat Sep 20 '12 at 11:01
Ah yes, you should use elseif() instead of else since you are checking conditions. – hampusn Sep 20 '12 at 11:04
Yeah, I figured it out - I was just about to post my findings - many thanks! – Ian Muscat Sep 20 '12 at 11:10

Your Answer


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

Browse other questions tagged or ask your own question.