WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/28/2014 09:11:11 PM (7 years ago)
Author:
johnbillion
Message:

Introduce a new means of outputting a <title> tag in the theme head. Requires a theme to add support by calling add_theme_support( 'title-tag' ). This is the first step in adding a more robust means of generating and outputting the title tag.

See #18548.
Props obenland, chrisbliss18, joostdevalk.

File:
1 edited

Legend:

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

    r29789 r30074  
    732732
    733733/**
     734 * Display <title> tag with contents.
     735 *
     736 * @since 4.1.0
     737 * @access private
     738 */
     739function _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' ) && ! doing_action( 'wp_head' ) ) {
     746        return;
     747    }
     748
     749    echo '<title>' . wp_title( '|', false, 'right' ) . "</title>\n";
     750}
     751
     752/**
    734753 * Display or retrieve page title for all areas of blog.
    735754 *
     
    754773 */
    755774function wp_title($sep = '&raquo;', $display = true, $seplocation = '') {
    756     global $wp_locale;
     775    global $wp_locale, $page, $paged;
    757776
    758777    $m = get_query_var('m');
     
    852871    } else {
    853872        $title = $prefix . implode( " $sep ", $title_array );
     873    }
     874
     875    if ( current_theme_supports( 'title-tag' ) && ! is_feed() ) {
     876        $title .= get_bloginfo( 'name', 'display' );
     877
     878        $site_description = get_bloginfo( 'description', 'display' );
     879        if ( $site_description && ( is_home() || is_front_page() ) ) {
     880            $title .= " $sep $site_description";
     881        }
     882
     883        if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
     884            $title .= " $sep " . sprintf( __( 'Page %s' ), max( $paged, $page ) );
     885        }
    854886    }
    855887
Note: See TracChangeset for help on using the changeset viewer.