How to set your own custom template page as default selected page in WordPress

set your own custom template page as default selected page in WordPress

If you wish to set your own custom template page as default selected WordPress template page, use the snippet below:

// set default template as your own custom page (it will select page autmatically)
add_action('admin_init', 'set_page_templates');
function set_page_templates()
{
    foreach (get_posts('post_type=page&posts_per_page=-1') as $page) {
        $current_template = get_post_meta($page->ID, '_wp_page_template', true);
        $new_template = 'custom-page.php';

        if ($current_template != $new_template)
            update_post_meta($page->ID, '_wp_page_template', $new_template);
    }
}

Here the custom-page.php is the template file which you have created. You can set the file name here.

Whenever you create a new page, that page will be selected automatically by default.

Related Posts