Make WordPress Core


Ignore:
Timestamp:
11/11/2015 11:49:31 PM (9 years ago)
Author:
obenland
Message:

Template: Un-deprecate wp_title().

Before it can be deprecated we should identify alternative usages and define
a path forward for them.

See [35294], #31078.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/deprecated.php

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