codemuffin

WordPress: Template file for handling the title (<h1>)

Jun 13th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2.  
  3. // Empty Archive
  4.     if ( is_404() && is_archive() ) : $page_title = 'Nothing Available';
  5.  
  6. // 404 Page
  7.     elseif ( is_404() && !is_archive() ) : $page_title = 'Nothing Found';
  8.  
  9. // Single Page
  10.     elseif ( is_page() ) : $page_title = get_the_title();
  11.  
  12. // Custom Post Archives
  13.     elseif ( is_post_type_archive() ) : $page_title = $wp_query->queried_object->label; // Custom post archive
  14.     elseif ( is_tax() ) : $page_title = $wp_query->queried_object->name; // Custom taxonomy archive
  15.  
  16. // Blog Archives
  17.     elseif ( is_home() )    : $page_title = 'Latest Posts';
  18.     elseif ( is_category() ): $page_title = 'Category Archives: <span>'. single_cat_title('', false) .'</span>';
  19.     elseif ( is_tag() ) : $page_title = 'Tag Archives: <span>'. single_tag_title('', false) .'</span>';
  20.     elseif ( is_author() )  : $page_title = 'Author Archives: <span>'. get_the_author(). '</span>';
  21.     elseif ( is_day() ) : $page_title = 'Daily Archives: <span>'. get_the_date(). '</span>';
  22.     elseif ( is_month() )   : $page_title = 'Monthly Archives: <span>'. get_the_date( 'F Y' ) .'</span>';
  23.     elseif ( is_year() )    : $page_title = 'Yearly Archives: <span>'. get_the_date( 'Y' ) .'</span>';
  24.  
  25. // Defaults to the title of the first post within the main query
  26.     else : $page_title = get_the_title();
  27.  
  28. // End of the whole IF 
  29.     endif;
  30.  
  31. // Output the H1 ?>
  32. <h1 class="entry-title page-title"><?php echo $page_title; ?></h1>
Add Comment
Please, Sign In to add comment