您可以添加检查以查看当前页面是否为主页,如果是,则跳过添加页面标题。这将使最终代码如下所示:
<title><?php
global $page, $paged;
// Add the page title if not the front page
if ( is_front_page() ) {
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\', \'twentyeleven\' ), max( $paged, $page ) );
?></title>
然而,最好的做法是在
header.php
:
<title><?php wp_title( \'|\', true, \'right\' ); ?></title>
然后在中使用此代码筛选标题
functions.php
:
function wpse_132052_wp_title( $title, $sep ) {
global $paged, $page;
// Add the blog name
$title .= get_bloginfo( \'name\' );
// Use the site name and description for the home/front page
if ( is_home() || is_front_page() ) {
$title = get_bloginfo( \'name\' );
// Add the site description for the home/front page.
$site_description = get_bloginfo( \'description\', \'display\' );
if ( $site_description && ( ) ) {
$title = "$title $sep $site_description";
}
}
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 ) {
echo \' | \' . sprintf( __( \'Page %s\', \'twentyeleven\' ), max( $paged, $page ) );
}
return $title;
}
add_filter( \'wp_title\', \'wpse_132052_wp_title\', 10, 2 );