Ticket #31078: 31078.2.diff
File 31078.2.diff, 13.5 KB (added by , 10 years ago) |
---|
-
src/wp-includes/deprecated.php
3563 3563 return apply_filters( 'htmledit_pre', $output ); 3564 3564 } 3565 3565 3566 /** 3567 * Display or retrieve page title for all areas of blog. 3568 * 3569 * By default, the page title will display the separator before the page title, 3570 * so that the blog title will be before the page title. This is not good for 3571 * title display, since the blog title shows up on most tabs and not what is 3572 * important, which is the page that the user is looking at. 3573 * 3574 * There are also SEO benefits to having the blog title after or to the 'right' 3575 * or the page title. However, it is mostly common sense to have the blog title 3576 * to the right with most browsers supporting tabs. You can achieve this by 3577 * using the seplocation parameter and setting the value to 'right'. This change 3578 * was introduced around 2.5.0, in case backwards compatibility of themes is 3579 * important. 3580 * 3581 * @since 1.0.0 3582 * @deprecated 4.3.0 3583 * @deprecated Use add_theme_support( 'title-tag' ); 3584 * 3585 * @param string $sep Optional, default is '»'. How to separate the various items within the page title. 3586 * @param bool $display Optional, default is true. Whether to display or retrieve title. 3587 * @param string $seplocation Optional. Direction to display title, 'right'. 3588 * @return string|null String on retrieve, null when displaying. 3589 */ 3590 function wp_title( $sep = '»', $display = true, $seplocation = '' ) { 3591 _deprecated_function( __FUNCTION__, '4.3', 'add_theme_support( \'title-tag\' )' ); 3592 3593 global $wp_locale; 3594 3595 $m = get_query_var( 'm' ); 3596 $year = get_query_var( 'year' ); 3597 $monthnum = get_query_var( 'monthnum' ); 3598 $day = get_query_var( 'day' ); 3599 $search = get_query_var( 's' ); 3600 $title = ''; 3601 3602 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary 3603 3604 // If there is a post 3605 if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) { 3606 $title = single_post_title( '', false ); 3607 } 3608 3609 // If there's a post type archive 3610 if ( is_post_type_archive() ) { 3611 $post_type = get_query_var( 'post_type' ); 3612 if ( is_array( $post_type ) ) { 3613 $post_type = reset( $post_type ); 3614 } 3615 $post_type_object = get_post_type_object( $post_type ); 3616 if ( ! $post_type_object->has_archive ) { 3617 $title = post_type_archive_title( '', false ); 3618 } 3619 } 3620 3621 // If there's a category or tag 3622 if ( is_category() || is_tag() ) { 3623 $title = single_term_title( '', false ); 3624 } 3625 3626 // If there's a taxonomy 3627 if ( is_tax() ) { 3628 $term = get_queried_object(); 3629 if ( $term ) { 3630 $tax = get_taxonomy( $term->taxonomy ); 3631 $title = single_term_title( $tax->labels->name . $t_sep, false ); 3632 } 3633 } 3634 3635 // If there's an author 3636 if ( is_author() && ! is_post_type_archive() ) { 3637 $author = get_queried_object(); 3638 if ( $author ) { 3639 $title = $author->display_name; 3640 } 3641 } 3642 3643 // Post type archives with has_archive should override terms. 3644 if ( is_post_type_archive() && $post_type_object->has_archive ) { 3645 $title = post_type_archive_title( '', false ); 3646 } 3647 3648 // If there's a month 3649 if ( is_archive() && ! empty( $m ) ) { 3650 $my_year = substr( $m, 0, 4 ); 3651 $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) ); 3652 $my_day = intval( substr( $m, 6, 2 ) ); 3653 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' ); 3654 } 3655 3656 // If there's a year 3657 if ( is_archive() && ! empty( $year ) ) { 3658 $title = $year; 3659 if ( ! empty( $monthnum ) ) { 3660 $title .= $t_sep . $wp_locale->get_month( $monthnum ); 3661 } 3662 if ( ! empty( $day ) ) { 3663 $title .= $t_sep . zeroise( $day, 2 ); 3664 } 3665 } 3666 3667 // If it's a search 3668 if ( is_search() ) { 3669 /* translators: 1: separator, 2: search phrase */ 3670 $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) ); 3671 } 3672 3673 // If it's a 404 page 3674 if ( is_404() ) { 3675 $title = __( 'Page not found' ); 3676 } 3677 3678 $prefix = ''; 3679 if ( ! empty( $title ) ) { 3680 $prefix = " $sep "; 3681 } 3682 3683 /** 3684 * Filter the parts of the page title. 3685 * 3686 * @since 4.0.0 3687 * 3688 * @param array $title_array Parts of the page title. 3689 */ 3690 $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); 3691 3692 // Determines position of the separator and direction of the breadcrumb 3693 if ( 'right' == $seplocation ) { // sep on right, so reverse the order 3694 $title_array = array_reverse( $title_array ); 3695 $title = implode( " $sep ", $title_array ) . $prefix; 3696 } else { 3697 $title = $prefix . implode( " $sep ", $title_array ); 3698 } 3699 3700 /** 3701 * Filter the text of the page title. 3702 * 3703 * @since 2.0.0 3704 * 3705 * @param string $title Page title. 3706 * @param string $sep Title separator. 3707 * @param string $seplocation Location of the separator (left or right). 3708 */ 3709 $title = apply_filters( 'wp_title', $title, $sep, $seplocation ); 3710 3711 // Send it out 3712 if ( $display ) { 3713 echo $title; 3714 } else { 3715 return $title; 3716 } 3717 } -
src/wp-includes/general-template.php
727 727 * @ignore 728 728 * @since 4.1.0 729 729 * @access private 730 *731 * @see wp_title()732 730 */ 733 731 function _wp_render_title_tag() { 734 732 if ( ! current_theme_supports( 'title-tag' ) ) { 735 733 return; 736 734 } 737 735 738 // This can only work internally on wp_head.739 if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {736 // If wp_title() has fired, don't do anything. 737 if ( did_action( 'wp_title' ) ) { 740 738 return; 741 739 } 742 740 743 echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n"; 744 } 741 /** 742 * Allows to short-circuit the title generation. 743 * 744 * @since 4.3.0 745 * 746 * @param string $title The document title. Default: Empty string. 747 */ 748 $title = apply_filters( 'title_tag_pre', '' ); 749 if ( ! empty( $title ) ) { 750 echo "<title>$title</title>\n"; 751 } 745 752 746 /** 747 * Display or retrieve page title for all areas of blog. 748 * 749 * By default, the page title will display the separator before the page title, 750 * so that the blog title will be before the page title. This is not good for 751 * title display, since the blog title shows up on most tabs and not what is 752 * important, which is the page that the user is looking at. 753 * 754 * There are also SEO benefits to having the blog title after or to the 'right' 755 * or the page title. However, it is mostly common sense to have the blog title 756 * to the right with most browsers supporting tabs. You can achieve this by 757 * using the seplocation parameter and setting the value to 'right'. This change 758 * was introduced around 2.5.0, in case backwards compatibility of themes is 759 * important. 760 * 761 * @since 1.0.0 762 * 763 * @global WP_Locale $wp_locale 764 * @global int $page 765 * @global int $paged 766 * 767 * @param string $sep Optional, default is '»'. How to separate the various items within the page title. 768 * @param bool $display Optional, default is true. Whether to display or retrieve title. 769 * @param string $seplocation Optional. Direction to display title, 'right'. 770 * @return string|void String on retrieve. 771 */ 772 function wp_title( $sep = '»', $display = true, $seplocation = '' ) { 773 global $wp_locale, $page, $paged; 753 global $page, $paged; 774 754 775 $m = get_query_var('m'); 776 $year = get_query_var('year'); 777 $monthnum = get_query_var('monthnum'); 778 $day = get_query_var('day'); 779 $search = get_query_var('s'); 780 $title = ''; 755 $title = array(); 781 756 782 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary 757 if ( is_home() && is_front_page() ) { 758 $title['page'] = get_bloginfo( 'name', 'display' ); 783 759 784 // If there is a post785 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page()) ) {786 $title = single_post_title( '', false );787 }760 $description = get_bloginfo( 'description', 'display' ); 761 if ( ! empty( $description ) ) { 762 $title['site'] = $description; 763 } 788 764 789 // If there's a post type archive 790 if ( is_post_type_archive() ) { 791 $post_type = get_query_var( 'post_type' ); 792 if ( is_array( $post_type ) ) 793 $post_type = reset( $post_type ); 794 $post_type_object = get_post_type_object( $post_type ); 795 if ( ! $post_type_object->has_archive ) 796 $title = post_type_archive_title( '', false ); 797 } 765 // If we're on the blog page and that page is not the homepage, use the container page's title. 766 } elseif ( is_home() && ! is_front_page() ) { 767 $title['page'] = get_post( get_option( 'page_for_posts' ) )->post_title; 798 768 799 // If there's a category or tag 800 if ( is_category() || is_tag() ) { 801 $title = single_term_title( '', false ); 802 } 769 // If it's a single page, that is designated as the homepage. 770 } elseif ( ! is_home() && is_front_page() ) { 771 $title['page'] = single_post_title( '', false ); 803 772 804 // If there's a taxonomy 805 if ( is_tax() ) { 806 $term = get_queried_object(); 807 if ( $term ) { 808 $tax = get_taxonomy( $term->taxonomy ); 809 $title = single_term_title( $tax->labels->name . $t_sep, false ); 773 // If we're on a post / page. 774 } elseif ( is_singular() ) { 775 $title['page'] = single_post_title( '', false ); 776 777 // If we're on a category or tag or taxonomy archive. 778 } elseif ( is_category() || is_tag() || is_tax() ) { 779 $title['page'] = single_term_title( '', false ); 780 781 // If it's a search. 782 } elseif ( is_search() ) { 783 /* translators: 1: search phrase */ 784 $title['page'] = sprintf( __( 'Search Results for “%1$s”' ), strip_tags( get_query_var( 's' ) ) ); 785 786 // If we're on an author archive. 787 } elseif ( is_author() ) { 788 if ( $author = get_queried_object() ) { 789 $title['page'] = $author->display_name; 810 790 } 811 }812 791 813 // If there's an author 814 if ( is_author() && ! is_post_type_archive() ) { 815 $author = get_queried_object(); 816 if ( $author ) 817 $title = $author->display_name; 818 } 792 // If we're on a post type archive. 793 } elseif ( is_post_type_archive() ) { 794 $title['page'] = post_type_archive_title( '', false ); 819 795 820 // Post type archives with has_archive should override terms. 821 if ( is_post_type_archive() && $post_type_object->has_archive ) 822 $title = post_type_archive_title( '', false ); 796 } elseif ( is_year() ) { 797 $title['page'] = get_the_date( _x( 'Y', 'yearly archives date format' ) ); 823 798 824 // If there's a month 825 if ( is_archive() && !empty($m) ) { 826 $my_year = substr($m, 0, 4); 827 $my_month = $wp_locale->get_month(substr($m, 4, 2)); 828 $my_day = intval(substr($m, 6, 2)); 829 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' ); 830 } 799 } elseif ( is_month() ) { 800 $title['page'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) ); 831 801 832 // If there's a year 833 if ( is_archive() && !empty($year) ) { 834 $title = $year; 835 if ( !empty($monthnum) ) 836 $title .= $t_sep . $wp_locale->get_month($monthnum); 837 if ( !empty($day) ) 838 $title .= $t_sep . zeroise($day, 2); 839 } 802 // If it's a date archive. 803 } elseif ( is_day() ) { 804 $title['page'] = get_the_date(); 840 805 841 // If it's a search 842 if ( is_search() ) { 843 /* translators: 1: separator, 2: search phrase */ 844 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search)); 806 // If it's a 404 page. 807 } elseif ( is_404() ) { 808 $title['page'] = __( 'Page not found' ); 845 809 } 846 810 847 // If it's a 404 page848 if ( is_404() ) {849 $title = __('Page not found');811 // Add a page number if necessary: 812 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { 813 $title['number'] = sprintf( __( 'Page %s' ), max( $paged, $page ) ); 850 814 } 851 815 852 $prefix = '';853 if ( !empty($title) )854 $prefix = " $sep ";816 if ( ! is_home() && ! is_front_page() ) { 817 $title['site'] = get_bloginfo( 'name', 'display' ); 818 } 855 819 856 820 /** 857 * Filter the parts of the pagetitle.821 * Filters the separator for the document title. 858 822 * 859 * @since 4. 0.0823 * @since 4.3.0 860 824 * 861 * @param array $title _array Parts of the page title.825 * @param array $title The separator. 862 826 */ 863 $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) ); 864 865 // Determines position of the separator and direction of the breadcrumb 866 if ( 'right' == $seplocation ) { // sep on right, so reverse the order 867 $title_array = array_reverse( $title_array ); 868 $title = implode( " $sep ", $title_array ) . $prefix; 869 } else { 870 $title = $prefix . implode( " $sep ", $title_array ); 871 } 872 873 if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) { 874 $title .= get_bloginfo( 'name', 'display' ); 875 876 $site_description = get_bloginfo( 'description', 'display' ); 877 if ( $site_description && ( is_home() || is_front_page() ) ) { 878 $title .= " $sep $site_description"; 879 } 880 881 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { 882 $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) ); 883 } 884 } 827 $sep = apply_filters( 'title_tag_separator', '|' ); 885 828 886 829 /** 887 * Filter the text of the pagetitle.830 * Filters the parts of the document title. 888 831 * 889 * @since 2.0.0832 * @since 4.3.0 890 833 * 891 * @param string $title Page title. 892 * @param string $sep Title separator. 893 * @param string $seplocation Location of the separator (left or right). 834 * @param array $title The document title parts. 894 835 */ 895 $title = apply_filters( ' wp_title', $title, $sep, $seplocation);836 $title = apply_filters( 'title_tag_parts', $title ); 896 837 897 // Send it out 898 if ( $display ) 899 echo $title; 900 else 901 return $title; 838 if ( is_rtl() ) { 839 $title = array_reverse( $title ); 840 } 841 $title = implode( " $sep ", $title ); 902 842 843 echo "<title>$title</title>\n"; 903 844 } 904 845 905 846 /**