Use the Page Template for a Custom Post Type
Displays single entries of chosen post types with your theme's page template instead of the blog post template, so they have no dates, authors or post navigation.
Opens WPIDE on
Code
// Post types shown with the page template.
$wpide_page_like_types = array( 'service', 'location' );
add_filter( 'single_template_hierarchy', function ( $templates ) use ( $wpide_page_like_types ) {
if ( ! is_singular( $wpide_page_like_types ) ) {
return $templates;
}
$pos = array_search( 'single.php', $templates, true );
array_splice( $templates, false === $pos ? count( $templates ) : $pos, 0, array( 'page.php' ) );
return $templates;
} );
Notes
Works with classic (page.php) and block themes (the "Pages" template). A single-{post_type} template still takes priority.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.