Change the name of the ‘Default Template’

I am working on a client’s site and they need to select a Template whenever they are adding a new page; the “Default Template” is not a valid choice.

I would like to rename “Default Template” to something like “– Select Template –“.

Read More

Searching the WordPress codebase I found references to “Default Template” are hard-coded, in wp-admin/includes/meta-boxes.php (line 588) and wp-admin/includes/class-wp-posts-list-table.php (line 882). Does this mean there is currently no way to change this, without altering the core code (something I want to avoid)?

Related posts

Leave a Reply

4 comments

  1. I agree with the answer that is given by @TravisPflanz but if you only want to change the name that is provided by the WordPress core you can use the following filter.

    function yourprefix_filter_gettext( $translation, $text, $domain ) {
        if ( $text == 'Default Template' ) {
            return __( 'Detail Page', 'your-theme-or-plugin-textdomain' );
        }
        return $translation;
    }
    add_filter( 'gettext', 'yourprefix_filter_gettext', 10, 3 );    
    

    This replaces the default core translation with one of your own.

    Please rename yourprefix and your-theme-or-plugin-textdomain to your configuration

  2. Your request, if I’m not mistaken, is to create an empty selection as the default for the page template drop-down, then force a user to select a custom page template.

    This may be an over-simplified answer, but you should create a default template that is a valid choice, then offer other templates to supplement the “Default Template”. Just make default the most basic possible page layout. This will eliminate confusion for the user as well. Just determine which will be the most common page layout and make it the “Default”.

    As Chip points out below, the “Default Template” always exists, even if you simply try to change the name using the traditional template naming methods. If you change the template name of page.php, you will simply be given the options of “Default Template” and the “New & Cool Page Template”.

  3. I hit problems with using a new page.php in the child theme to define a different default template, so instead I using an

    add_action( 'after_setup_theme'...
    

    to setup a global option using

    update_option ('default_template','page-content.php');
    

    I then used

    function replace_page_attributes_metaboxes() {
        add_meta_box('post-parent', 'Page attributes', 'attributes_meta_box', 
                 'page', 'side', 'high');
        remove_meta_box('pageparentdiv', 'page', 'side'); 
    } 
    add_action( 'admin_menu' , 'replace_page_attributes_metaboxes' );
    

    to delete the standard Page Attributes metabox that is used to define the Page Template and replace it with a copy of the code (see http://wpseek.com/page_attributes_meta_box/). I replaced the section of the code that finds the page template name with:

    if ( ($post->post_type == 'page')  && (count( get_page_templates() ) != 0) ) {
        if (!empty($post->page_template))
            $template = $post->page_template;
        else
            $template =     get_option ('default_template');
    }
    

    if no option is found $template is set to false, which makes the underlying code pick up the standard default template.