-
-
Save hirejordansmith/9a9a7fc72dbdb714c9608614c6213c61 to your computer and use it in GitHub Desktop.
How to change which page template is set as default template for WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} | |
} |
I think this function isen't working anymore with the new WP version.
Can't get it working on my websites
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the code!
2 questions:
Sorry, not a WP developer :-)