From 24e099bb3e535ff28acf7658b39824eb90aa370e Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Fri, 15 Mar 2013 18:16:47 +0000 Subject: [PATCH] Twenty Ten: use a filter to modify the output of `wp_title()`. Props obenland, closes #23774. git-svn-id: http://core.svn.wordpress.org/trunk@23719 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/twentyten/functions.php | 32 +++++++++++++++++++++++ wp-content/themes/twentyten/header.php | 22 +--------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/wp-content/themes/twentyten/functions.php b/wp-content/themes/twentyten/functions.php index ea5f8c5244..3e8fd3bd26 100644 --- a/wp-content/themes/twentyten/functions.php +++ b/wp-content/themes/twentyten/functions.php @@ -514,3 +514,35 @@ function twentyten_posted_in() { ); } endif; + +/** + * Creates a nicely formatted and more specific title element text + * for output in head of document, based on current view. + * + * @since Twenty Ten 1.6 + * + * @param string $title Default title text for current view. + * @param string $sep Optional separator. + * @return string Filtered title. + */ +function twentyten_wp_title( $title, $sep ) { + global $paged, $page; + + if ( is_feed() ) + return $title; + + // Add the site name. + $title .= get_bloginfo( 'name' ); + + // Add the site description for the home/front page. + $site_description = get_bloginfo( 'description', 'display' ); + if ( $site_description && ( is_home() || is_front_page() ) ) + $title = "$title $sep $site_description"; + + // Add a page number if necessary. + if ( $paged >= 2 || $page >= 2 ) + $title = "$title $sep " . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); + + return $title; +} +add_filter( 'wp_title', 'twentyten_wp_title', 10, 2 ); diff --git a/wp-content/themes/twentyten/header.php b/wp-content/themes/twentyten/header.php index 50cb37589d..41eaea52f1 100644 --- a/wp-content/themes/twentyten/header.php +++ b/wp-content/themes/twentyten/header.php @@ -12,27 +12,7 @@ > -<?php - /* - * Print the <title> tag based on what is being viewed. - */ - global $page, $paged; - - wp_title( '|', true, 'right' ); - - // Add the blog name. - bloginfo( 'name' ); - - // Add the blog description for the home/front page. - $site_description = get_bloginfo( 'description', 'display' ); - if ( $site_description && ( is_home() || is_front_page() ) ) - echo " | $site_description"; - - // Add a page number if necessary: - if ( $paged >= 2 || $page >= 2 ) - echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); - - ?> +<?php wp_title( '|', true, 'right' ); ?>