Make WordPress Core

Changeset 23718


Ignore:
Timestamp:
03/15/2013 06:15:58 PM (13 years ago)
Author:
lancewillett
Message:

Twenty Eleven: use a filter to modify the output of wp_title(). Props obenland, see #23774.

Location:
trunk/wp-content/themes/twentyeleven
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyeleven/functions.php

    r23474 r23718  
    615615add_filter( 'body_class', 'twentyeleven_body_classes' );
    616616
     617/**
     618 * Creates a nicely formatted and more specific title element text
     619 * for output in head of document, based on current view.
     620 *
     621 * @since Twenty Eleven 1.6
     622 *
     623 * @param string $title Default title text for current view.
     624 * @param string $sep Optional separator.
     625 * @return string Filtered title.
     626 */
     627function twentyeleven_wp_title( $title, $sep ) {
     628    global $paged, $page;
     629
     630    if ( is_feed() )
     631        return $title;
     632
     633    // Add the site name.
     634    $title .= get_bloginfo( 'name' );
     635
     636    // Add the site description for the home/front page.
     637    $site_description = get_bloginfo( 'description', 'display' );
     638    if ( $site_description && ( is_home() || is_front_page() ) )
     639        $title = "$title $sep $site_description";
     640
     641    // Add a page number if necessary.
     642    if ( $paged >= 2 || $page >= 2 )
     643        $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );
     644
     645    return $title;
     646}
     647add_filter( 'wp_title', 'twentyeleven_wp_title', 10, 2 );
  • trunk/wp-content/themes/twentyeleven/header.php

    r20983 r23718  
    2525<meta charset="<?php bloginfo( 'charset' ); ?>" />
    2626<meta name="viewport" content="width=device-width" />
    27 <title><?php
    28     /*
    29      * Print the <title> tag based on what is being viewed.
    30      */
    31     global $page, $paged;
    32 
    33     wp_title( '|', true, 'right' );
    34 
    35     // Add the blog name.
    36     bloginfo( 'name' );
    37 
    38     // Add the blog description for the home/front page.
    39     $site_description = get_bloginfo( 'description', 'display' );
    40     if ( $site_description && ( is_home() || is_front_page() ) )
    41         echo " | $site_description";
    42 
    43     // Add a page number if necessary:
    44     if ( $paged >= 2 || $page >= 2 )
    45         echo ' | ' . sprintf( __( 'Page %s', 'twentyeleven' ), max( $paged, $page ) );
    46 
    47     ?></title>
     27<title><?php wp_title( '|', true, 'right' ); ?></title>
    4828<link rel="profile" href="http://gmpg.org/xfn/11" />
    4929<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
Note: See TracChangeset for help on using the changeset viewer.