Skip to content

Instantly share code, notes, and snippets.

@digisavvy
Created February 27, 2020 15:08
Show Gist options
  • Select an option

  • Save digisavvy/21c8b0626f7a0f826833b162bf7340c8 to your computer and use it in GitHub Desktop.

Select an option

Save digisavvy/21c8b0626f7a0f826833b162bf7340c8 to your computer and use it in GitHub Desktop.
function wpse196289_default_page_template() {
global $post;
if ( 'page' == $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 = "page-mytemplate.php";
}
}
add_action('add_meta_boxes', 'wpse196289_default_page_template', 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment