Skip to content

Snippet: Display Post Tile For Custom Post Type Post in Page Title Instead of Post Type Name

Important: If you are using the Post Types Unlimited plugin you can set this via the plugin settings without having to use custom code. Also since Total 5.4.6 you can now change the default title for your portfolio, staff and testimonials via the Customizer.

By default your custom post types display the post type in the main page header/title because the post title is displayed on the post itself so this prevents duplicate title issues. If you want to display the post title in the main page header/title do so with the following snippet added to your child theme's functions.php file.

function myprefix_alter_page_header_title( $title ) {
	if ( is_singular( 'YOUR_POST_TYPE_NAME' ) ) {
		return get_the_title();
	}
	return $title;
}
add_filter( 'wpex_title', 'myprefix_alter_page_header_title', 40 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top