Saturday , August 19 2017
Home / Developers / Change the default page template selection

Change the default page template selection

First, you will need this hook:
add_action(‘add_meta_boxes‘, ‘city_default_page_template‘, 1);

After that, add the following code:
function city_default_page_template() {
global $post;
if ( ‘city’ == $post->post_type
&& 0 != count( get_page_templates( $post ) )
&& get_option( ‘page_for_posts‘ ) != $post->ID // Not the page for listing posts
&&== $post->page_template // Only when page_template is not set
) {
$post->page_template =cpt-city-template.php“;
}
}

It should look like this:
Change the default page template selection

Add this to your functions.php file.

Leave a Reply

Your email address will not be published. Required fields are marked *