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