如果你看看source of wp_title()
您将看到,没有为静态首页计划输出。
使用the_title()
如@Chris\\u O所建议的,用于视觉输出。但是为了在<head>
必须筛选的节wp_title()
如果它是空的,就把它装满。
示例代码(download from GitHub):
// Hook in very late, let the theme fix it first.
add_filter( \'wp_title\', \'t5_fill_static_front_page_title\', 100 );
/**
* Fill empty front page title if a static page is set.
*
* @wp-hook wp_title
* @param string $title Existing title
* @return string
*/
function t5_fill_static_front_page_title( $title )
{
// another filter may have fixed this already.
if ( \'\' !== $title or ! is_page() or ! is_front_page() )
{
return $title;
}
$page_id = get_option( \'page_on_front\' );
$page = get_page( $page_id );
if ( ! $page or \'\' === $page->post_title )
{
$title = get_option( \'blogname\' );
}
else
{
$title = $page->post_title;
}
// We don’t know if there is any output after the title, so we cannot just
// add the separator. We use an empty space instead.
return "$title ";
}