Global Layout - how to set default for new pages

I’d like to follow up on this post:

When I create a new page, I’m having to execute these steps to go through these steps: “WP Editor > Page Attributes > Template” each time I create a new page.

I’d like a specific template to be used all the time without having to use what’s labeled ‘default template’.

How do I make ‘Blank - No Container | Header, Footer’ the new default template for future pages that I create?

Hi Gregory,

Thanks for reaching out.

That could be possible, please check this https://wordpress.stackexchange.com/questions/196289/is-there-a-way-to-change-the-default-page-template-selection. Then implement the code to your child theme’s functions.php

Example,

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 = "template-blank-4.php";
    }
}
add_action('add_meta_boxes', 'wpse196289_default_page_template', 1);

This may only work on newly created pages, hence, if you wish to force it for all existing pages. Then implement this code instead of that code

add_filter( 'template_include', 'default_page_template', 99 );

function default_page_template( $template ) {

    if ( is_singular( 'page' )  ) {
        $default_template = locate_template( array( 'template-blank-4.php' ) );
        if ( '' != $default_template ) {
            return $default_template ;
        }
    }

    return $template;
}

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.