| | 620 | * Display <title> tag with contents |
| | 621 | * |
| | 622 | * Possible arguments: |
| | 623 | * 'sep' string, for the separator used in title tags |
| | 624 | * 'home-title' string, for the homepage title. Only used for the blog page when the blog page is also the frontpage. |
| | 625 | * 'frontpage-title' string, for the front page when it's not the posts page. |
| | 626 | * 'show-sitename' boolean, defaults to true. When set to false the site name will not be added to titles. |
| | 627 | * |
| | 628 | * @since 3.3 |
| | 629 | * |
| | 630 | * @param string|array $args Optional. Override defaults. |
| | 631 | */ |
| | 632 | function wp_title_tag( $args = '' ) { |
| | 633 | // Allow early filtering, if this returns a title skip all the logic below and print it, if it returns false, bail completely |
| | 634 | if ( null !== $pre = apply_filters( 'pre_wp_title_tag', null ) ) { |
| | 635 | if ( $pre ) |
| | 636 | echo '<title>' . $pre . "<title>\n"; |
| | 637 | return; |
| | 638 | } |
| | 639 | |
| | 640 | $defaults = array( |
| | 641 | 'sep' => '-', |
| | 642 | 'home-title' => false, |
| | 643 | 'frontpage-title' => false, |
| | 644 | 'show-sitename' => true, |
| | 645 | ); |
| | 646 | |
| | 647 | $r = wp_parse_args( $args, $defaults ); |
| | 648 | |
| | 649 | global $page, $paged, $wp_locale; |
| | 650 | |
| | 651 | $title = array(); |
| | 652 | |
| | 653 | if ( is_home() && is_front_page() ) { |
| | 654 | if ( $r['home-title'] ) { |
| | 655 | $title[] = $r['home-title']; |
| | 656 | } else { |
| | 657 | $title[] = get_bloginfo('name'); |
| | 658 | |
| | 659 | // Add a page number if necessary: |
| | 660 | if ( $paged >= 2 || $page >= 2 ) |
| | 661 | $title[] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); |
| | 662 | |
| | 663 | if ( '' != $desc = get_bloginfo( 'description', 'display' ) ) |
| | 664 | $title[] = $desc; |
| | 665 | } |
| | 666 | // If we're on the blog page and that page is not the homepage, use the container page's title |
| | 667 | } elseif ( is_home() && !is_front_page() ) { |
| | 668 | $_post = get_post( get_option('page_for_posts') ); |
| | 669 | $title[] = $_post->post_title; |
| | 670 | |
| | 671 | // Add a page number if necessary: |
| | 672 | if ( $paged >= 2 || $page >= 2 ) |
| | 673 | $title[] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); |
| | 674 | |
| | 675 | if ( $r['show-sitename'] ) |
| | 676 | $title[] = get_bloginfo('name'); |
| | 677 | } elseif ( !is_home() && is_front_page() ) { |
| | 678 | if ( $r['frontpage-title'] ) { |
| | 679 | $title[] = $r['frontpage-title']; |
| | 680 | } else { |
| | 681 | $title[] = single_post_title( '', false ); |
| | 682 | |
| | 683 | if ( $r['show-sitename'] ) |
| | 684 | $title[] = get_bloginfo('name'); |
| | 685 | } |
| | 686 | } else { |
| | 687 | // If we're on a post / page |
| | 688 | if ( is_singular() ) { |
| | 689 | $title[] = single_post_title( '', false ); |
| | 690 | } |
| | 691 | |
| | 692 | // If we're on a category or tag archive |
| | 693 | elseif ( is_category() || is_tag() ) { |
| | 694 | $title[] = single_term_title( '', false ); |
| | 695 | } |
| | 696 | |
| | 697 | // If we're on a taxonomy archive |
| | 698 | elseif ( is_tax() ) { |
| | 699 | $term = get_queried_object(); |
| | 700 | $tax = get_taxonomy( $term->taxonomy ); |
| | 701 | $title[] = single_term_title( $tax->labels->name, false ); |
| | 702 | } |
| | 703 | |
| | 704 | // If we're on an author archive |
| | 705 | elseif ( is_author() ) { |
| | 706 | $author = get_queried_object(); |
| | 707 | $title[] = $author->display_name; |
| | 708 | } |
| | 709 | |
| | 710 | // If we're on a post type archive |
| | 711 | elseif ( is_post_type_archive() ) { |
| | 712 | $title[] = post_type_archive_title( '', false ); |
| | 713 | } |
| | 714 | |
| | 715 | // If it's a date archive |
| | 716 | elseif ( is_date() ) { |
| | 717 | $month = get_query_var('monthnum'); |
| | 718 | $day = get_query_var('day'); |
| | 719 | |
| | 720 | $t = ''; |
| | 721 | if ( !empty($month) ) { |
| | 722 | $month = $wp_locale->get_month($month); |
| | 723 | if ( !empty($day) ) |
| | 724 | $t .= zeroise($day, 2) . ' '; |
| | 725 | $t .= $month . ' '; |
| | 726 | } |
| | 727 | $title[] = $t . get_query_var('year'); |
| | 728 | } |
| | 729 | |
| | 730 | // If it's a search |
| | 731 | elseif ( is_search() ) { |
| | 732 | /* translators: 1: search phrase */ |
| | 733 | $title[] = sprintf(__('Search Results for "%1$s"'), strip_tags( get_query_var('s') ) ); |
| | 734 | } |
| | 735 | |
| | 736 | // If it's a 404 page |
| | 737 | elseif ( is_404() ) { |
| | 738 | $title[] = __('Page not found'); |
| | 739 | } |
| | 740 | |
| | 741 | // Add a page number if necessary: |
| | 742 | if ( $paged >= 2 || $page >= 2 ) |
| | 743 | $title[] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); |
| | 744 | |
| | 745 | if ( $r['show-sitename'] ) |
| | 746 | $title[] = get_bloginfo('name'); |
| | 747 | } |
| | 748 | $title = apply_filters( 'wp_title_tag_array', $title ); |
| | 749 | |
| | 750 | $title = implode( " ".$r['sep']." ", $title ); |
| | 751 | |
| | 752 | $title = apply_filters( 'wp_title_tag', $title, $r['sep'] ); |
| | 753 | echo "<title>" . $title . "</title>\n"; |
| | 754 | } |
| | 755 | |
| | 756 | /** |