如何将自定义帖子类型添加到页面标题,我指的是标题中标记中的标题。它应该是这样的:网页名称|产品>索尼Playstation 4
谢谢你!
如何将自定义帖子类型添加到页面标题,我指的是标题中标记中的标题。它应该是这样的:网页名称|产品>索尼Playstation 4
谢谢你!
您可以尝试以下操作:
/**
* Modify the header title on single pages
* but exclude the \'post\', \'attachment\' and \'page\' post types.
*
* Header Title: Site Name | Post Type Label | Post Title
*
* Example: My Shopping Site | Products | Sony Playstation 4
*/
function wpse_141145_wp_title( $title, $sep ) {
if( is_single() && \'post\' !== ( $pt = get_post_type() ) )
{
// Get the current post type object\'s \'singular name\' else \'name\':
$pto = get_post_type_object( $pt );
$pto_lsn = $pto->labels->singular_name;
$pto_ln = $pto->labels->name;
$pto_title = ( ! empty( $pto_lsn ) ) ) ? $pto_lsn : $pto_ln ;
// Space around the separator:
$sep = sprintf( \' %s \', trim( $sep ) );
// Construct the breadcrumb:
$title = get_bloginfo( \'name\', \'display\' );
$title .= $sep;
$title .= $pto_title;
$title .= $sep;
$title .= single_post_title( \'\', FALSE );
}
return esc_attr( $title );
}
add_filter( \'wp_title\', \'wpse_141145_wp_title\', 99, 2 );
在这里,我们修改了单个页面上的标题,但排除了post类型。然后我们回忆起is_single()
排除页面和附件的帖子类型。你是指这种修改,还是你另有打算?
我在我的网站的头文件中使用这个。<title><?php wp_title( \'|\', true, \'right\' ); ?></title> 但在网站所有页面的标题末尾都会显示“|”,如下所示<title>Our Company - SEO Company 1SEOIN |</title> 我要删除此“|”。我该怎么做?