WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm modifying the install.php (coping in from upgrade.php) file to load default pages that get created with a new blog is registered.

Im trying to find out how i can specify the page template that the new page will be assigned.

is there anything like page_template =>? Ive searched the codex but dont seem to find anything, or i have the wrong syntax idea.

current page code by default is:

  $first_page = sprintf( __( "This is an example page. As a new WordPress user, you should go to <a href=\"%s\">your dashboard</a> to delete this page and create new pages for your content. Have fun!" ), admin_url() );

  if ( is_multisite() )
        $first_page = get_site_option( 'first_page', $first_page );

  $first_post_guid = get_option('home') . '/?page_id=2';
    $wpdb->insert( $wpdb->posts, array(
                                'post_author' => $user_id,
                                'post_date' => $now,
                                'post_date_gmt' => $now_gmt,
                                'post_content' => $first_page,
                                'post_excerpt' => '',
                                'post_title' => __( 'Sample Page' ),
                                /* translators: Default page slug */
                                'post_name' => __( 'sample-page' ),
                                'post_modified' => $now,
                                'post_modified_gmt' => $now_gmt,
                                'guid' => $first_post_guid,
                                'post_type' => 'page',
                                'to_ping' => '',
                                'pinged' => '',
                                'post_content_filtered' => ''
    $wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'default' ) );
share|improve this question
up vote 2 down vote accepted

I dont think there is anything like page_template=> but you can just specify the template like this:

update_post_meta($id, "_wp_page_template", "new_template.php");

http://codex.wordpress.org/Function_Reference/update_post_meta or using your code above:

$wpdb->insert( $wpdb->postmeta, array( 'post_id' => 2, 'meta_key' => '_wp_page_template', 'meta_value' => 'new_template.php' ) );
share|improve this answer
Thanks! Probably will just use the plugin "default blog" as an overall solution but very handy code above, appreciated! – petergus Dec 14 '11 at 10:03

Your Answer


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.