Make WordPress Core

Ticket #31078: 31078.8.diff

File 31078.8.diff, 31.7 KB (added by obenland, 9 years ago)

wp_title_rss and documentation and usage updates.

  • src/wp-includes/deprecated.php

     
    36343634        _deprecated_function( __FUNCTION__, '4.4', 'force_ssl_admin()' );
    36353635        return force_ssl_admin( $force );
    36363636}
     3637
     3638/**
     3639 * Formerly used to display or retrieve page title for all areas of blog.
     3640 *
     3641 * By default, the page title will display the separator before the page title,
     3642 * so that the blog title will be before the page title. This is not good for
     3643 * title display, since the blog title shows up on most tabs and not what is
     3644 * important, which is the page that the user is looking at.
     3645 *
     3646 * There are also SEO benefits to having the blog title after or to the 'right'
     3647 * or the page title. However, it is mostly common sense to have the blog title
     3648 * to the right with most browsers supporting tabs. You can achieve this by
     3649 * using the seplocation parameter and setting the value to 'right'. This change
     3650 * was introduced around 2.5.0, in case backwards compatibility of themes is
     3651 * important.
     3652 *
     3653 * @since 1.0.0
     3654 * @deprecated 4.4.0
     3655 * @deprecated Use add_theme_support( 'title-tag' );
     3656 *
     3657 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
     3658 * @param bool $display Optional, default is true. Whether to display or retrieve title.
     3659 * @param string $seplocation Optional. Direction to display title, 'right'.
     3660 * @return string|null String on retrieve, null when displaying.
     3661 */
     3662function wp_title( $sep = '»', $display = true, $seplocation = '' ) {
     3663        _deprecated_function( __FUNCTION__, '4.4', 'add_theme_support( \'title-tag\' )' );
     3664
     3665        global $wp_locale;
     3666
     3667        $m        = get_query_var( 'm' );
     3668        $year     = get_query_var( 'year' );
     3669        $monthnum = get_query_var( 'monthnum' );
     3670        $day      = get_query_var( 'day' );
     3671        $search   = get_query_var( 's' );
     3672        $title    = '';
     3673
     3674        $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     3675
     3676        // If there is a post
     3677        if ( is_single() || ( is_home() && ! is_front_page() ) || ( is_page() && ! is_front_page() ) ) {
     3678                $title = single_post_title( '', false );
     3679        }
     3680
     3681        // If there's a post type archive
     3682        if ( is_post_type_archive() ) {
     3683                $post_type = get_query_var( 'post_type' );
     3684                if ( is_array( $post_type ) ) {
     3685                        $post_type = reset( $post_type );
     3686                }
     3687                $post_type_object = get_post_type_object( $post_type );
     3688                if ( ! $post_type_object->has_archive ) {
     3689                        $title = post_type_archive_title( '', false );
     3690                }
     3691        }
     3692
     3693        // If there's a category or tag
     3694        if ( is_category() || is_tag() ) {
     3695                $title = single_term_title( '', false );
     3696        }
     3697
     3698        // If there's a taxonomy
     3699        if ( is_tax() ) {
     3700                $term = get_queried_object();
     3701                if ( $term ) {
     3702                        $tax   = get_taxonomy( $term->taxonomy );
     3703                        $title = single_term_title( $tax->labels->name . $t_sep, false );
     3704                }
     3705        }
     3706
     3707        // If there's an author
     3708        if ( is_author() && ! is_post_type_archive() ) {
     3709                $author = get_queried_object();
     3710                if ( $author ) {
     3711                        $title = $author->display_name;
     3712                }
     3713        }
     3714
     3715        // Post type archives with has_archive should override terms.
     3716        if ( is_post_type_archive() && $post_type_object->has_archive ) {
     3717                $title = post_type_archive_title( '', false );
     3718        }
     3719
     3720        // If there's a month
     3721        if ( is_archive() && ! empty( $m ) ) {
     3722                $my_year  = substr( $m, 0, 4 );
     3723                $my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
     3724                $my_day   = intval( substr( $m, 6, 2 ) );
     3725                $title    = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
     3726        }
     3727
     3728        // If there's a year
     3729        if ( is_archive() && ! empty( $year ) ) {
     3730                $title = $year;
     3731                if ( ! empty( $monthnum ) ) {
     3732                        $title .= $t_sep . $wp_locale->get_month( $monthnum );
     3733                }
     3734                if ( ! empty( $day ) ) {
     3735                        $title .= $t_sep . zeroise( $day, 2 );
     3736                }
     3737        }
     3738
     3739        // If it's a search
     3740        if ( is_search() ) {
     3741                /* translators: 1: separator, 2: search phrase */
     3742                $title = sprintf( __( 'Search Results %1$s %2$s' ), $t_sep, strip_tags( $search ) );
     3743        }
     3744
     3745        // If it's a 404 page
     3746        if ( is_404() ) {
     3747                $title = __( 'Page not found' );
     3748        }
     3749
     3750        $prefix = '';
     3751        if ( ! empty( $title ) ) {
     3752                $prefix = " $sep ";
     3753        }
     3754
     3755        /**
     3756         * Filter the parts of the page title.
     3757         *
     3758         * @since 4.0.0
     3759         *
     3760         * @param array $title_array Parts of the page title.
     3761         */
     3762        $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
     3763
     3764        // Determines position of the separator and direction of the breadcrumb
     3765        if ( 'right' == $seplocation ) { // sep on right, so reverse the order
     3766                $title_array = array_reverse( $title_array );
     3767                $title       = implode( " $sep ", $title_array ) . $prefix;
     3768        } else {
     3769                $title = $prefix . implode( " $sep ", $title_array );
     3770        }
     3771
     3772        /**
     3773         * Filter the text of the page title.
     3774         *
     3775         * @since 2.0.0
     3776         *
     3777         * @param string $title Page title.
     3778         * @param string $sep Title separator.
     3779         * @param string $seplocation Location of the separator (left or right).
     3780         */
     3781        $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     3782
     3783        // Send it out
     3784        if ( $display ) {
     3785                echo $title;
     3786        } else {
     3787                return $title;
     3788        }
     3789}
  • src/wp-includes/feed-atom-comments.php

     
    3333                elseif ( is_search() )
    3434                        printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    3535                else
    36                         printf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() );
     36                        printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    3737        ?></title>
    3838        <subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle>
    3939
  • src/wp-includes/feed-atom.php

     
    2727  do_action( 'atom_ns' );
    2828  ?>
    2929 >
    30         <title type="text"><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     30        <title type="text"><?php wp_title_rss(); ?></title>
    3131        <subtitle type="text"><?php bloginfo_rss("description") ?></subtitle>
    3232
    3333        <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></updated>
  • src/wp-includes/feed-rdf.php

     
    3030        ?>
    3131>
    3232<channel rdf:about="<?php bloginfo_rss("url") ?>">
    33         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     33        <title><?php wp_title_rss(); ?></title>
    3434        <link><?php bloginfo_rss('url') ?></link>
    3535        <description><?php bloginfo_rss('description') ?></description>
    3636        <dc:date><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_lastpostmodified('GMT'), false); ?></dc:date>
  • src/wp-includes/feed-rss.php

     
    1111echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
    1212<rss version="0.92">
    1313<channel>
    14         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     14        <title><?php wp_title_rss(); ?></title>
    1515        <link><?php bloginfo_rss('url') ?></link>
    1616        <description><?php bloginfo_rss('description') ?></description>
    1717        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
  • src/wp-includes/feed-rss2-comments.php

     
    3838                elseif ( is_search() )
    3939                        printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    4040                else
    41                         printf( ent2ncr( __( 'Comments for %s' ) ), get_bloginfo_rss( 'name' ) . get_wp_title_rss() );
     41                        printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    4242        ?></title>
    4343        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    4444        <link><?php (is_single()) ? the_permalink_rss() : bloginfo_rss("url") ?></link>
  • src/wp-includes/feed-rss2.php

     
    3838>
    3939
    4040<channel>
    41         <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
     41        <title><?php wp_title_rss(); ?></title>
    4242        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
    4343        <link><?php bloginfo_rss('url') ?></link>
    4444        <description><?php bloginfo_rss("description") ?></description>
  • src/wp-includes/feed.php

     
    9191 * Retrieve the blog title for the feed title.
    9292 *
    9393 * @since 2.2.0
     94 * @since 4.4.0 Deprecated argument.
    9495 *
    95  * @param string $sep Optional. How to separate the title. See wp_title() for more info.
    96  * @return string Error message on failure or blog title on success.
     96 * @param string $deprecated Deprecated.
     97 * @return string The document title.
    9798 */
    98 function get_wp_title_rss( $sep = '&#187;' ) {
    99         $title = wp_title( $sep, false );
    100 
    101         if ( is_wp_error( $title ) ) {
    102                 return $title->get_error_message();
    103         }
    104 
    105         if ( $title && $sep && ' ' !== substr( $title, 0, 1 ) ) {
    106                 $title = " $sep " . $title;
     99function get_wp_title_rss( $deprecated = '&#8211;' ) {
     100        if ( '&#8211;' !== $deprecated ) {
     101                _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>title_tag_separator</code>' ) );
    107102        }
    108103
    109104        /**
     
    111106         *
    112107         * @since 2.2.0
    113108         *
    114          * @param string $title The current blog title.
    115          * @param string $sep   Separator used by wp_title().
     109         * @param string $title      The current blog title.
     110         * @param string $deprecated Deprecated.
    116111         */
    117         $title = apply_filters( 'get_wp_title_rss', $title, $sep );
    118         return $title;
     112        return apply_filters( 'get_wp_title_rss', _wp_get_title(), $deprecated );
    119113}
    120114
    121115/**
    122116 * Display the blog title for display of the feed title.
    123117 *
    124118 * @since 2.2.0
    125  * @see wp_title() $sep parameter usage.
     119 * @since 4.4.0 Deprecated argument.
    126120 *
    127  * @param string $sep Optional.
     121 * @param string $deprecated Optional.
    128122 */
    129 function wp_title_rss( $sep = '&#187;' ) {
     123function wp_title_rss( $deprecated = '&#8211;' ) {
     124        if ( '&#8211;' !== $deprecated ) {
     125                _deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>title_tag_separator</code>' ) );
     126        }
     127
    130128        /**
    131129         * Filter the blog title for display of the feed title.
    132130         *
     
    134132         *
    135133         * @see get_wp_title_rss()
    136134         *
    137          * @param string $wp_title The current blog title.
    138          * @param string $sep      Separator used by wp_title().
     135         * @param string $wp_title_rss The current blog title.
     136         * @param string $deprecated   Deprecated.
    139137         */
    140         echo apply_filters( 'wp_title_rss', get_wp_title_rss( $sep ), $sep );
     138        echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated );
    141139}
    142140
    143141/**
  • src/wp-includes/general-template.php

     
    775775}
    776776
    777777/**
    778  * Display title tag with contents.
     778 * Returns title tag with contents.
    779779 *
    780780 * @ignore
    781  * @since 4.1.0
     781 * @since 4.4.0
    782782 * @access private
    783783 *
    784  * @see wp_title()
     784 * @global int $page
     785 * @global int $paged
     786 *
     787 * @return string Tag with the document title.
    785788 */
    786 function _wp_render_title_tag() {
    787         if ( ! current_theme_supports( 'title-tag' ) ) {
    788                 return;
    789         }
     789function _wp_get_title() {
    790790
    791         // This can only work internally on wp_head.
    792         if ( ! did_action( 'wp_head' ) && ! doing_action( 'wp_head' ) ) {
    793                 return;
     791        /**
     792         * Allows to short-circuit the title generation.
     793         *
     794         * @since 4.4.0
     795         *
     796         * @param string $title The document title. Default empty string.
     797         */
     798        $title = apply_filters( 'title_tag_pre', '' );
     799        if ( ! empty( $title ) ) {
     800                return $title;
    794801        }
    795802
    796         echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
    797 }
     803        global $page, $paged;
    798804
    799 /**
    800  * Display or retrieve page title for all areas of blog.
    801  *
    802  * By default, the page title will display the separator before the page title,
    803  * so that the blog title will be before the page title. This is not good for
    804  * title display, since the blog title shows up on most tabs and not what is
    805  * important, which is the page that the user is looking at.
    806  *
    807  * There are also SEO benefits to having the blog title after or to the 'right'
    808  * or the page title. However, it is mostly common sense to have the blog title
    809  * to the right with most browsers supporting tabs. You can achieve this by
    810  * using the seplocation parameter and setting the value to 'right'. This change
    811  * was introduced around 2.5.0, in case backwards compatibility of themes is
    812  * important.
    813  *
    814  * @since 1.0.0
    815  *
    816  * @global WP_Locale $wp_locale
    817  * @global int       $page
    818  * @global int       $paged
    819  *
    820  * @param string $sep         Optional, default is '&raquo;'. How to separate the various items within the page title.
    821  * @param bool   $display     Optional, default is true. Whether to display or retrieve title.
    822  * @param string $seplocation Optional. Direction to display title, 'right'.
    823  * @return string|void String on retrieve.
    824  */
    825 function wp_title( $sep = '&raquo;', $display = true, $seplocation = '' ) {
    826         global $wp_locale, $page, $paged;
     805        $title = array(
     806                'title' => '',
     807        );
    827808
    828         $m = get_query_var('m');
    829         $year = get_query_var('year');
    830         $monthnum = get_query_var('monthnum');
    831         $day = get_query_var('day');
    832         $search = get_query_var('s');
    833         $title = '';
     809        if ( is_home() && is_front_page() ) {
     810                $title['title'] = get_bloginfo( 'name', 'display' );
    834811
    835         $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
     812                /*
     813                 * If we're on the blog page and that page is not the homepage or a single page that is designated as
     814                 * the homepage, use the container page's title.
     815                 */
     816        } elseif ( ( is_home() && ! is_front_page() ) || ( ! is_home() && is_front_page() ) ) {
     817                $title['title'] = single_post_title( '', false );
    836818
    837         // If there is a post
    838         if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
    839                 $title = single_post_title( '', false );
    840         }
     819                // If we're on a post / page.
     820        } elseif ( is_singular() ) {
     821                $title['title'] = single_post_title( '', false );
     822
     823                // If we're on a category or tag or taxonomy archive.
     824        } elseif ( is_category() || is_tag() || is_tax() ) {
     825                $title['title'] = single_term_title( '', false );
    841826
    842         // If there's a post type archive
    843         if ( is_post_type_archive() ) {
    844                 $post_type = get_query_var( 'post_type' );
    845                 if ( is_array( $post_type ) )
    846                         $post_type = reset( $post_type );
    847                 $post_type_object = get_post_type_object( $post_type );
    848                 if ( ! $post_type_object->has_archive )
    849                         $title = post_type_archive_title( '', false );
    850         }
     827                // If it's a search.
     828        } elseif ( is_search() ) {
     829                /* translators: %s: search phrase */
     830                $title['title'] = sprintf( __( 'Search Results for &#8220;%s&#8221;' ), get_search_query() );
    851831
    852         // If there's a category or tag
    853         if ( is_category() || is_tag() ) {
    854                 $title = single_term_title( '', false );
    855         }
     832                // If we're on an author archive.
     833        } elseif ( is_author() && $author = get_queried_object() ) {
     834                $title['title'] = $author->display_name;
    856835
    857         // If there's a taxonomy
    858         if ( is_tax() ) {
    859                 $term = get_queried_object();
    860                 if ( $term ) {
    861                         $tax = get_taxonomy( $term->taxonomy );
    862                         $title = single_term_title( $tax->labels->name . $t_sep, false );
    863                 }
    864         }
     836                // If we're on a post type archive.
     837        } elseif ( is_post_type_archive() ) {
     838                $title['title'] = post_type_archive_title( '', false );
    865839
    866         // If there's an author
    867         if ( is_author() && ! is_post_type_archive() ) {
    868                 $author = get_queried_object();
    869                 if ( $author )
    870                         $title = $author->display_name;
    871         }
     840                // If it's a date archive.
     841        } elseif ( is_year() ) {
     842                $title['title'] = get_the_date( _x( 'Y', 'yearly archives date format' ) );
    872843
    873         // Post type archives with has_archive should override terms.
    874         if ( is_post_type_archive() && $post_type_object->has_archive )
    875                 $title = post_type_archive_title( '', false );
     844        } elseif ( is_month() ) {
     845                $title['title'] = get_the_date( _x( 'F Y', 'monthly archives date format' ) );
    876846
    877         // If there's a month
    878         if ( is_archive() && !empty($m) ) {
    879                 $my_year = substr($m, 0, 4);
    880                 $my_month = $wp_locale->get_month(substr($m, 4, 2));
    881                 $my_day = intval(substr($m, 6, 2));
    882                 $title = $my_year . ( $my_month ? $t_sep . $my_month : '' ) . ( $my_day ? $t_sep . $my_day : '' );
    883         }
     847        } elseif ( is_day() ) {
     848                $title['title'] = get_the_date();
    884849
    885         // If there's a year
    886         if ( is_archive() && !empty($year) ) {
    887                 $title = $year;
    888                 if ( !empty($monthnum) )
    889                         $title .= $t_sep . $wp_locale->get_month($monthnum);
    890                 if ( !empty($day) )
    891                         $title .= $t_sep . zeroise($day, 2);
     850                // If it's a 404 page.
     851        } elseif ( is_404() ) {
     852                $title['title'] = __( 'Page not found' );
    892853        }
    893854
    894         // If it's a search
    895         if ( is_search() ) {
    896                 /* translators: 1: separator, 2: search phrase */
    897                 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
     855        // Add a page number if necessary:
     856        if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
     857                $title['page'] = sprintf( __( 'Page %s' ), max( $paged, $page ) );
    898858        }
    899859
    900         // If it's a 404 page
    901         if ( is_404() ) {
    902                 $title = __('Page not found');
     860        // Append the description or site title to give context.
     861        if ( is_home() && is_front_page() ) {
     862                $title['tagline'] = get_bloginfo( 'description', 'display' );
     863        } else {
     864                $title['site'] = get_bloginfo( 'name', 'display' );
    903865        }
    904866
    905         $prefix = '';
    906         if ( !empty($title) )
    907                 $prefix = " $sep ";
    908 
    909867        /**
    910          * Filter the parts of the page title.
     868         * Filters the separator for the document title.
    911869         *
    912          * @since 4.0.0
     870         * @since 4.4.0
    913871         *
    914          * @param array $title_array Parts of the page title.
     872         * @param string $sep The separator. Default '-'.
    915873         */
    916         $title_array = apply_filters( 'wp_title_parts', explode( $t_sep, $title ) );
    917 
    918         // Determines position of the separator and direction of the breadcrumb
    919         if ( 'right' == $seplocation ) { // sep on right, so reverse the order
    920                 $title_array = array_reverse( $title_array );
    921                 $title = implode( " $sep ", $title_array ) . $prefix;
    922         } else {
    923                 $title = $prefix . implode( " $sep ", $title_array );
    924         }
    925 
    926         if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
    927                 $title .= get_bloginfo( 'name', 'display' );
    928 
    929                 $site_description = get_bloginfo( 'description', 'display' );
    930                 if ( $site_description && ( is_home() || is_front_page() ) ) {
    931                         $title .= " $sep $site_description";
    932                 }
    933 
    934                 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
    935                         $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
    936                 }
    937         }
     874        $sep = apply_filters( 'title_tag_separator', '-' );
    938875
    939876        /**
    940          * Filter the text of the page title.
     877         * Filters the parts of the document title.
    941878         *
    942          * @since 2.0.0
     879         * @since 4.4.0
    943880         *
    944          * @param string $title       Page title.
    945          * @param string $sep         Title separator.
    946          * @param string $seplocation Location of the separator (left or right).
    947          */
    948         $title = apply_filters( 'wp_title', $title, $sep, $seplocation );
     881         * @param array $title {
     882         *     The document title parts.
     883         *
     884         *     @type string $title   Title of the viewed page.
     885         *     @type string $page    Optional. Page number if paginated.
     886         *     @type string $tagline Optional. Site description when on home page.
     887         *     @type string $site    Optional. Site title when not on home page.
     888         * }
     889         */
     890        $title = apply_filters( 'title_tag_parts', $title );
     891
     892        $title = implode( " $sep ", array_filter( $title ) );
     893        $title = wptexturize( $title );
     894        $title = convert_chars( $title );
     895        $title = esc_html( $title );
     896        $title = capital_P_dangit( $title );
    949897
    950         // Send it out
    951         if ( $display )
    952                 echo $title;
    953         else
    954                 return $title;
     898        return $title;
     899}
    955900
     901/**
     902 * Display title tag with contents.
     903 *
     904 * @ignore
     905 * @since 4.1.0
     906 * @since 4.4.0 Improved title output replaced `wp_title()`.
     907 * @access private
     908 */
     909function _wp_render_title_tag() {
     910        if ( ! current_theme_supports( 'title-tag' ) ) {
     911                return;
     912        }
     913
     914        echo '<title>' . _wp_get_title() . '</title>' . "\n";
    956915}
    957916
    958917/**
     
    1033992/**
    1034993 * Display or retrieve page title for category archive.
    1035994 *
    1036  * This is useful for category template file or files, because it is optimized
    1037  * for category page title and with less overhead than {@link wp_title()}.
    1038  *
    1039  * It does not support placing the separator after the title, but by leaving the
    1040  * prefix parameter empty, you can set the title separator manually. The prefix
    1041  * does not automatically place a space between the prefix, so if there should
    1042  * be a space, the parameter value will need to have it at the end.
     995 * Useful for category template files for displaying the category page title.
     996 * The prefix does not automatically place a space between the prefix, so if
     997 * there should be a space, the parameter value will need to have it at the end.
    1043998 *
    1044999 * @since 0.71
    10451000 *
     
    10541009/**
    10551010 * Display or retrieve page title for tag post archive.
    10561011 *
    1057  * Useful for tag template files for displaying the tag page title. It has less
    1058  * overhead than {@link wp_title()}, because of its limited implementation.
    1059  *
    1060  * It does not support placing the separator after the title, but by leaving the
    1061  * prefix parameter empty, you can set the title separator manually. The prefix
     1012 * Useful for tag template files for displaying the tag page title. The prefix
    10621013 * does not automatically place a space between the prefix, so if there should
    10631014 * be a space, the parameter value will need to have it at the end.
    10641015 *
     
    10761027 * Display or retrieve page title for taxonomy term archive.
    10771028 *
    10781029 * Useful for taxonomy term template files for displaying the taxonomy term page title.
    1079  * It has less overhead than {@link wp_title()}, because of its limited implementation.
    1080  *
    1081  * It does not support placing the separator after the title, but by leaving the
    1082  * prefix parameter empty, you can set the title separator manually. The prefix
    1083  * does not automatically place a space between the prefix, so if there should
     1030 * The prefix does not automatically place a space between the prefix, so if there should
    10841031 * be a space, the parameter value will need to have it at the end.
    10851032 *
    10861033 * @since 3.1.0
     
    11381085/**
    11391086 * Display or retrieve page title for post archive based on date.
    11401087 *
    1141  * Useful for when the template only needs to display the month and year, if
    1142  * either are available. Optimized for just this purpose, so if it is all that
    1143  * is needed, should be better than {@link wp_title()}.
    1144  *
    1145  * It does not support placing the separator after the title, but by leaving the
    1146  * prefix parameter empty, you can set the title separator manually. The prefix
    1147  * does not automatically place a space between the prefix, so if there should
    1148  * be a space, the parameter value will need to have it at the end.
     1088 * Useful for when the template only needs to display the month and year,
     1089 * if either are available. The prefix does not automatically place a space
     1090 * between the prefix, so if there should be a space, the parameter value
     1091 * will need to have it at the end.
    11491092 *
    11501093 * @since 0.71
    11511094 *
  • src/wp-includes/theme-compat/header.php

     
    1515<link rel="profile" href="http://gmpg.org/xfn/11" />
    1616<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    1717
    18 <title><?php wp_title('&laquo;', true, 'right'); ?> <?php bloginfo('name'); ?></title>
     18<?php _wp_render_title_tag(); ?>
    1919
    2020<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
    2121<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
  • src/wp-includes/theme.php

     
    17521752        if ( !isset( $_wp_theme_features[$feature] ) )
    17531753                return false;
    17541754
    1755         if ( 'title-tag' == $feature ) {
    1756                 // Don't confirm support unless called internally.
    1757                 $trace = debug_backtrace();
    1758                 if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) {
    1759                         return false;
    1760                 }
    1761         }
    1762 
    17631755        // If no args passed then no extra checks need be performed
    17641756        if ( func_num_args() <= 1 )
    17651757                return true;
  • tests/phpunit/tests/general/document-title.php

     
     1<?php
     2
     3/**
     4 * A set of unit tests for functions in wp-includes/general-template.php
     5 *
     6 * @group template
     7 * @group document-title
     8 */
     9class Tests_Document_Title extends WP_UnitTestCase {
     10
     11        function setUp() {
     12                parent::setUp();
     13
     14                add_action( 'after_setup_theme', array( $this, '_add_title_tag_support' ) );
     15
     16                $this->category_id = $this->factory->category->create( array(
     17                        'name' => 'test_category',
     18                ) );
     19
     20                $this->author_id = $this->factory->user->create( array(
     21                        'role'        => 'author',
     22                        'user_login'  => 'test_author',
     23                        'description' => 'test_author',
     24                ) );
     25
     26                $this->post_id = $this->factory->post->create( array(
     27                        'post_author'  => $this->author_id,
     28                        'post_status'  => 'publish',
     29                        'post_content' => rand_str(),
     30                        'post_title'   => 'test_title',
     31                        'post_type'    => 'post',
     32                        'post_date'    => '2015-09-22 18:52:17',
     33                        'category'     => $this->category_id,
     34                ) );
     35
     36                setup_postdata( get_post( $this->post_id ) );
     37        }
     38
     39        function tearDown() {
     40                wp_reset_postdata();
     41                parent::tearDown();
     42        }
     43
     44        function _add_title_tag_support() {
     45                add_theme_support( 'title-tag' );
     46        }
     47
     48        function test_short_circuiting_title() {
     49                $this->go_to( '/' );
     50
     51                add_filter( 'title_tag_pre', array( $this, '_short_circuit_title' ) );
     52
     53                $this->expectOutputString( "<title>A Wild Title</title>\n" );
     54                _wp_render_title_tag();
     55        }
     56
     57        function _short_circuit_title( $title ) {
     58                return 'A Wild Title';
     59        }
     60
     61        function test_front_page_title() {
     62                update_option( 'show_on_front', 'page' );
     63                update_option( 'page_for_posts', $this->factory->post->create( array( 'post_title' => 'blog-page', 'post_type' => 'page' ) ) );
     64                update_option( 'page_on_front', $this->factory->post->create( array( 'post_title' => 'front-page', 'post_type' => 'page' ) ) );
     65
     66                $this->go_to( '/' );
     67
     68                $this->expectOutputString( "<title>front-page &#8211; Test Blog</title>\n" );
     69                _wp_render_title_tag();
     70
     71                update_option( 'show_on_front', 'posts' );
     72        }
     73
     74        function test_home_title() {
     75                $this->go_to( '/' );
     76
     77                add_filter( 'title_tag_parts', array( $this, '_home_title_parts' ) );
     78
     79                $this->expectOutputString( "<title>Test Blog &#8211; Just another WordPress site</title>\n" );
     80                _wp_render_title_tag();
     81        }
     82
     83        function _home_title_parts( $parts ) {
     84                $this->assertArrayHasKey( 'title', $parts );
     85                $this->assertArrayHasKey( 'tagline', $parts );
     86                $this->assertArrayNotHasKey( 'site', $parts );
     87
     88                return $parts;
     89        }
     90
     91        function test_paged_title() {
     92                $this->go_to( '?page=4' );
     93
     94                add_filter( 'title_tag_parts', array( $this, '_paged_title_parts' ) );
     95
     96                $this->expectOutputString( "<title>Test Blog &#8211; Page 4 &#8211; Just another WordPress site</title>\n" );
     97                _wp_render_title_tag();
     98        }
     99
     100        function _paged_title_parts( $parts ) {
     101                $this->assertArrayHasKey( 'page', $parts );
     102                $this->assertArrayHasKey( 'title', $parts );
     103                $this->assertArrayHasKey( 'tagline', $parts );
     104                $this->assertArrayNotHasKey( 'site', $parts );
     105
     106                return $parts;
     107        }
     108
     109        function test_singular_title() {
     110                $this->go_to( '?p=' . $this->post_id );
     111
     112                add_filter( 'title_tag_parts', array( $this, '_singular_title_parts' ) );
     113
     114                $this->expectOutputString( "<title>test_title &#8211; Test Blog</title>\n" );
     115                _wp_render_title_tag();
     116        }
     117
     118        function _singular_title_parts( $parts ) {
     119                $this->assertArrayHasKey( 'site', $parts );
     120                $this->assertArrayHasKey( 'title', $parts );
     121                $this->assertArrayNotHasKey( 'tagline', $parts );
     122
     123                return $parts;
     124        }
     125
     126        function test_category_title() {
     127                $this->go_to( '?cat=' . $this->category_id );
     128
     129                $this->expectOutputString( "<title>test_category &#8211; Test Blog</title>\n" );
     130                _wp_render_title_tag();
     131        }
     132
     133        function test_search_title() {
     134                $this->go_to( '?s=test_title' );
     135
     136                $this->expectOutputString( "<title>Search Results for &#8220;test_title&#8221; &#8211; Test Blog</title>\n" );
     137                _wp_render_title_tag();
     138        }
     139
     140        function test_author_title() {
     141                $this->go_to( '?author=' . $this->author_id );
     142
     143                $this->expectOutputString( "<title>test_author &#8211; Test Blog</title>\n" );
     144                _wp_render_title_tag();
     145        }
     146
     147        function test_post_type_archive_title() {
     148                register_post_type( 'cpt', array(
     149                        'public'      => true,
     150                        'has_archive' => true,
     151                        'labels'      => array(
     152                                'name' => 'test_cpt',
     153                        ),
     154                ) );
     155
     156                $this->factory->post->create( array(
     157                        'post_type' => 'cpt',
     158                ) );
     159
     160                $this->go_to( '?post_type=cpt' );
     161
     162                $this->expectOutputString( "<title>test_cpt &#8211; Test Blog</title>\n" );
     163                _wp_render_title_tag();
     164        }
     165
     166        function test_year_title() {
     167                $this->go_to( '?year=2015' );
     168
     169                $this->expectOutputString( "<title>2015 &#8211; Test Blog</title>\n" );
     170                _wp_render_title_tag();
     171        }
     172
     173        function test_month_title() {
     174                $this->go_to( '?monthnum=09' );
     175
     176                $this->expectOutputString( "<title>September 2015 &#8211; Test Blog</title>\n" );
     177                _wp_render_title_tag();
     178        }
     179
     180        function test_day_title() {
     181                $this->go_to( '?day=22' );
     182
     183                $this->expectOutputString( "<title>September 22, 2015 &#8211; Test Blog</title>\n" );
     184                _wp_render_title_tag();
     185        }
     186
     187        function test_404_title() {
     188                $this->go_to( '?m=404' );
     189
     190                $this->expectOutputString( "<title>Page not found &#8211; Test Blog</title>\n" );
     191                _wp_render_title_tag();
     192        }
     193
     194        function test_paged_post_title() {
     195                $this->go_to( '?paged=4&p=' . $this->post_id );
     196
     197                add_filter( 'title_tag_parts', array( $this, '_paged_post_title_parts' ) );
     198
     199                $this->expectOutputString( "<title>test_title &#8211; Page 4 &#8211; Test Blog</title>\n" );
     200                _wp_render_title_tag();
     201        }
     202
     203        function _paged_post_title_parts( $parts ) {
     204                $this->assertArrayHasKey( 'page', $parts );
     205                $this->assertArrayHasKey( 'site', $parts );
     206                $this->assertArrayHasKey( 'title', $parts );
     207                $this->assertArrayNotHasKey( 'tagline', $parts );
     208
     209                return $parts;
     210        }
     211
     212        function test_rearrange_title_parts() {
     213                $this->go_to( '?p=' . $this->post_id );
     214
     215                add_filter( 'title_tag_parts', array( $this, '_rearrange_title_parts' ) );
     216
     217                $this->expectOutputString( "<title>Test Blog &#8211; test_title</title>\n" );
     218                _wp_render_title_tag();
     219        }
     220
     221        function _rearrange_title_parts( $parts ) {
     222                $parts = array(
     223                        $parts['site'],
     224                        $parts['title'],
     225                );
     226
     227                return $parts;
     228        }
     229
     230        function test_change_title_separator() {
     231                $this->go_to( '?p=' . $this->post_id );
     232
     233                add_filter( 'title_tag_separator', array( $this, '_change_title_separator' ) );
     234
     235                $this->expectOutputString( "<title>test_title %% Test Blog</title>\n" );
     236                _wp_render_title_tag();
     237        }
     238
     239        function _change_title_separator( $sep ) {
     240                return '%%';
     241        }
     242}