Changing the default page template

Changing the default page template in a child theme

The first way of doing this is by making a new copy of page.php in the child theme directory, which is automatically picked up as the default.   This can cause problems with plugins that expect a fairly simple page.php (e.g. BuddyPress).

An alternative is to define a new copy of the ‘Page Attributes’ metabox which can pick up a default template value and hiding the old template box.

The new default template name can be setup as follows within the theme’s functions.php, where page-content.php is replaced with the name of the default file

function set_default_template()
{
 update_option ('default_template','page-content.php');
}
add_action( 'after_setup_theme', 'set_default_template' );

The ‘Page Attributes’ box code should also be inserted into functions.php from here.  The standard metabox should be removed and the new metabox should be inserted using

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' );

and the code that finds the current or default template replaced 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');
 }

 

 


Notice: Undefined index: edit_posts in /home/coherent/thedyers.org.uk/wp-content/plugins/allow-page-authors/allow-page-authors.php on line 389