我希望wordpress显示所选文章和所选页面的标题。我正在使用商业新闻主题。他们有任何设置可用吗?或者我需要更改代码。我是wordpress的新手。我在header.php 中找到了标题代码
<title><?php
//Print the <title> tag based on what is being viewed.
global $page, $paged;
// 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', 'business-news' ), max( $paged, $page ) );
?></title>
但当我选择颗粒帖子时,它只显示标题中的网站名称。我在哪里失踪了?
试试这个:
<title>
<?php single_post_title(); ?>
</title>
使用add_filter wp_title()函数进行管理
<title><?php wp_title(''); ?></title>
如果你想在function.php中使用类似的方法进行更改
function theme_name_wp_title( $title, $sep ) {
if ( is_feed() ) {
return $title;
}
global $page, $paged;
// Add the blog name
$title .= get_bloginfo( 'name', 'display' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) ) {
$title .= " $sep $site_description";
}
// Add a page number if necessary:
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) {
$title .= " $sep " . sprintf( __( 'Page %s', '_s' ), max( $paged, $page ) );
}
return $title;
}
add_filter( 'wp_title', 'theme_name_wp_title', 10, 2 );
您可以简单地使用:
<title><?php wp_title(); ?></title>
有关更多帮助,请访问此处