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