Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 --".

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)?

share|improve this question
    
Can you explain why "Default Template" is not a valid choice? –  Chip Bennett Apr 12 '12 at 13:09
    
Because I'm using Advanced Custom Fields and depending on the theme you select a completely different set of fields appears, there is no one we could set as "Default" and be happy with. –  Shaun Apr 12 '12 at 16:29
    
But something has to be the default. In WordPress, static Pages must have a Template, and will always fall back to page.php and then to index.php. –  Chip Bennett Apr 12 '12 at 18:15
    
It could be done with jquery/js i guess, if you really want to enforce it, naturally though a user could bypass the restriction by disabling js or blocking the script file that enforces a template choice. –  t31os Apr 13 '13 at 19:18
add comment

3 Answers

up vote 2 down vote accepted

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".

share|improve this answer
    
The "Default Template" always exists, as defined by the WordPress Template Hierarchy for static Pages. –  Chip Bennett Apr 12 '12 at 14:08
    
OK thanks. As I commented above, we really need them to choose a theme as there is no good style we could automatically set as "Default" and be happy with. We will have to leave it how it is, and tell them to change from "Default Theme" to any other. –  Shaun Apr 12 '12 at 16:31
add comment

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

share|improve this answer
    
Some notes: strict (===) checks are faster. And you should remove the action when you found the string. This filter runs several thousand times during each request and has a big impact on performance. –  kaiser Feb 25 at 11:43
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.