Make WordPress Core


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

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

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.