How can I add the custom post type to the title of the page, I mean the title in the tag in the header. It should look something like this: Webpage name | Products > Sony Playstation 4
Thanks ahead!
You can try this:
/**
* 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 );
where we modify the header title on single pages, but exclude the post post type.
We then recall that is_single()
excludes the page and attachment post types.
Did you mean this kind of modification or did you have something else in mind?
esc_attr
the title before returning it.