| 734 | * Display <title> tag with contents. |
| 735 | * |
| 736 | * @since 4.1.0 |
| 737 | * @access private |
| 738 | */ |
| 739 | function _wp_render_title_tag() { |
| 740 | if ( ! current_theme_supports( 'title-tag' ) ) { |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | // This can only work internally on wp_head. |
| 745 | if ( ! did_action( 'wp_head' ) && ( ! function_exists( 'doing_action' ) || ! doing_action( 'wp_head' ) ) ) { |
| 746 | return; |
| 747 | } |
| 748 | |
| 749 | // If wp_title() has fired, don't do anything. |
| 750 | if ( did_action( 'wp_title' ) ) { |
| 751 | return; |
| 752 | } |
| 753 | |
| 754 | // Allow early filtering, if this returns a title skip all the logic below and print it. |
| 755 | if ( null !== $pre = apply_filters( 'pre_wp_title_tag', null ) ) { |
| 756 | echo "<title>$pre<title>\n"; |
| 757 | |
| 758 | return; |
| 759 | } |
| 760 | |
| 761 | global $page, $paged, $wp_locale; |
| 762 | |
| 763 | $title = array(); |
| 764 | |
| 765 | if ( is_home() && is_front_page() ) { |
| 766 | $title[] = get_bloginfo( 'name', 'display' ); |
| 767 | |
| 768 | $description = get_bloginfo( 'description', 'display' ); |
| 769 | if ( ! empty( $description ) ) { |
| 770 | $title[] = $description; |
| 771 | } |
| 772 | |
| 773 | // If we're on the blog page and that page is not the homepage, use the container page's title |
| 774 | } elseif ( is_home() && ! is_front_page() ) { |
| 775 | $title[] = get_post( get_option( 'page_for_posts' ) )->post_title; |
| 776 | |
| 777 | } elseif ( ! is_home() && is_front_page() ) { |
| 778 | $title[] = single_post_title( '', false ); |
| 779 | |
| 780 | // If we're on a post / page |
| 781 | } elseif ( is_singular() ) { |
| 782 | $title[] = single_post_title( '', false ); |
| 783 | |
| 784 | // If we're on a category or tag or taxonomy archive |
| 785 | } elseif ( is_category() || is_tag() || is_tax() ) { |
| 786 | $title[] = single_term_title( '', false ); |
| 787 | |
| 788 | // If it's a search |
| 789 | } elseif ( is_search() ) { |
| 790 | /* translators: 1: search phrase */ |
| 791 | $title[] = sprintf( esc_html__( 'Search Results for "%1$s"' ), strip_tags( get_query_var( 's' ) ) ); |
| 792 | |
| 793 | // If we're on an author archive |
| 794 | } elseif ( is_author() ) { |
| 795 | if ( $author = get_queried_object() ) { |
| 796 | $title[] = $author->display_name; |
| 797 | } |
| 798 | |
| 799 | // If we're on a post type archive |
| 800 | } elseif ( is_post_type_archive() ) { |
| 801 | $title[] = post_type_archive_title( '', false ); |
| 802 | |
| 803 | } elseif ( is_year() ) { |
| 804 | $title[] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); |
| 805 | |
| 806 | } elseif ( is_month() ) { |
| 807 | $title[] = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); |
| 808 | |
| 809 | // If it's a date archive |
| 810 | } elseif ( is_day() ) { |
| 811 | $title[] = get_the_date(); |
| 812 | |
| 813 | // If it's a 404 page |
| 814 | } elseif ( is_404() ) { |
| 815 | $title[] = esc_html__( 'Page not found' ); |
| 816 | } |
| 817 | |
| 818 | // Add a page number if necessary: |
| 819 | if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { |
| 820 | $title[] = sprintf( esc_html__( 'Page %s' ), max( $paged, $page ) ); |
| 821 | } |
| 822 | |
| 823 | if ( ! is_home() && ! is_front_page() ) { |
| 824 | $title[] = get_bloginfo( 'name', 'display' ); |
| 825 | } |
| 826 | |
| 827 | $title = apply_filters( 'wp_title_tag_array', $title ); |
| 828 | |
| 829 | // sep, defaults to - as the separator between two parts of the title |
| 830 | $sep = '|'; |
| 831 | |
| 832 | $title = implode( " $sep ", $title ); |
| 833 | $title = apply_filters( 'wp_title_tag', $title, $sep ); |
| 834 | |
| 835 | echo "<title>$title</title>\n"; |
| 836 | } |
| 837 | |
| 838 | /** |