Advertisement
Guest User

Untitled

a guest
May 30th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. /**
  2. * Template tag:
  3. * Get <title> text
  4. * Use as <title><?php echo get_site_title( '-' ); ?></title>
  5. * @param string $separator String separator
  6. * @return string title text
  7. */
  8. function get_site_title( $separator = ' – ' ) {
  9. global $wp_query;
  10.  
  11. $title = array();
  12.  
  13. // global site title
  14. $title['global'] = get_bloginfo( 'name' );
  15.  
  16. // single / page
  17. $title['single'] = ( is_single() || is_page() ) ? get_the_title() : 0;
  18.  
  19. // custom post type
  20. $title['post_type'] = 0;
  21. if( !empty( $wp_query->query['post_type'] ) ) {
  22. $post_type = get_post_type_object( $wp_query->query['post_type'] );
  23. $title['post_type'] = $post_type->labels->name;
  24. }
  25.  
  26. // paged
  27. $title['paged'] = ( !empty( $wp_query->query['paged'] ) ) ? __( 'Page' ) . ' ' . $wp_query->query['paged'] : 0;
  28.  
  29. // date archive
  30. $title['date'] = 0;
  31. if( is_date() ) {
  32. if( is_year() ) {
  33. $title['date'] = $wp_query->query['year'];
  34. }
  35.  
  36. if( is_month() ) {
  37. $title['date'] = $wp_query->query['monthnum'] . $separator . $wp_query->query['year'];
  38. }
  39.  
  40. if( is_day() ) {
  41. $title['date'] = $wp_query->query['day'] . $separator . $wp_query->query['monthnum'] . $separator . $wp_query->query['year'];
  42. }
  43. }
  44.  
  45. // tags
  46. $title['tag'] = ( is_tag() ) ? __( 'Tag' ) . ': ' . single_cat_title( '', false ) : 0;
  47.  
  48. //categories
  49. $title['tag'] = ( is_category() ) ? __( 'Category' ) . ': ' . single_cat_title( '', false ) : 0;
  50.  
  51. // custom taxonomy terms
  52. $title['term'] = 0;
  53. if( !empty( $wp_query->query_vars['term'] ) ) {
  54. $taxonomy_labels = get_taxonomy_labels( get_taxonomy( $wp_query->query_vars['taxonomy'] ) );
  55. $term = get_term_by( 'slug', $wp_query->query_vars['term'], $wp_query->query_vars['taxonomy'] );
  56. if( $taxonomy_labels && $term ) {
  57. $title['term'] = $taxonomy_labels->name . ': ' . $term->name;
  58. }
  59. }
  60.  
  61. // author
  62. $title['author'] = 0;
  63. if( !empty( $wp_query->query['author_name'] ) ) {
  64. $author = get_user_by( 'slug', $wp_query->query['author_name'] );
  65. $title['author'] = $author->first_name . ' ' . $author->last_name;
  66. }
  67.  
  68. $title_string = '';
  69. $title_string .= ( $title['single'] ) ? $title['single'] . $separator : '';
  70. $title_string .= ( $title['term'] ) ? $title['term'] . $separator : '';
  71. $title_string .= ( $title['tag'] ) ? $title['tag'] . $separator : '';
  72. $title_string .= ( $title['post_type'] ) ? $title['post_type'] . $separator : '';
  73. $title_string .= ( $title['date'] ) ? $title['date'] . $separator : '';
  74. $title_string .= ( $title['author'] ) ? $title['author'] . $separator : '';
  75. $title_string .= ( $title['paged'] ) ? $title['paged'] . $separator : '';
  76. $title_string .= $title['global'];
  77.  
  78. return $title_string;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement