您可以尝试以下操作:
/**
* 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()
排除页面和附件的帖子类型。
你是指这种修改,还是你另有打算?