【发布时间】:2012-12-23 02:55:41
【问题描述】:
我无法让我的自定义 WordPress 主题中的标题正确显示。标题属性设置如下:<title><?php wp_title( '|', true, 'right' ); ?></title>
我直接从 2012 主题中获取了该代码。当我激活 2012 主题时,标题看起来很完美,但是当我使用上面相同代码的自定义主题时,我将我的网站地址作为主页上的标题,而在其他每个页面上,我只得到页面名称后跟一个“|”。知道是什么原因造成的吗?我已经寻找了第二个标题标签,但到目前为止还没有。它破坏了我的 SEO。
将此添加到我的functions.php:
function twentytwelve_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', 'twentytwelve' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 );
【问题讨论】:
-
如果您发布屏幕截图或页面链接(最好是后者),会更容易回答您的问题。此外,正如 @j08691 所提到的,请务必仔细检查 WordPress Codex。他们在记录 CMS 的每个功能方面做得非常出色。