Page Automatically Generated from Theme?

I’m running WordPress multisite and would like each site to have a specific page (with pre-loaded content) generated from a page template, contact.php. Rather than go through each site and create this page, I would like it to be created automatically by the theme. I plan to add all the content in contact.php itself. I’m assuming there is a way I can do this with a theme hack but have no idea where to start.

To put it more simply, the theme would automatically create a page at domain.com/contact from the template contact.php.

Related posts

1 comment

  1. Put this in your functions.php file:

    $contact_query = new WP_Query(array(
        'pagename' => 'contact',
        'post_type' => 'page',
        'post_status' => 'publish',
        'posts_per_page' => 1,
    ));
    if (! $contact_query->post_count)
        wp_insert_post(array(
            'post_name' => 'contact',
            'post_title' => 'Contact',
            'post_status' => 'publish',
            'post_type' => 'page',
            'post_author' => 1,
            'page_template' => 'page-contact.php',
        ));
    unset($contact_query);
    

    What does it do?
    If the contact page does not exist, create it.

Comments are closed.