I recently had a page template that needed to be set as the default page template INSTEAD OF the “Default Template”
I dig some digging and found a solution that works exactly as expected.
Here is how to change which WordPress page template is set as default template.
Make sure to update “post” to “page” if needed.
Also make sure to update “listing-template.php” with your own template filename.
That’s it enjoy! 🙂
<?php | |
add_action('add_meta_boxes', 'hjs_default_page_template', 1); | |
function hjs_default_page_template() { | |
global $post; | |
if ( 'post' == $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 = "listing-template.php"; | |
} | |
} |
Leave a Reply