Halloween Sale 15% off Ends in See the plans
PHP

Create Starter Pages on New Network Sites

Creates a set of pages such as About, Contact and Privacy on every new site, and can set one of them as the static front page.

Don’t have WPIDE yet? Install it on your site

Code

if ( ! is_multisite() ) {
    return;
}

$wpide_pages = array( // Title => content.
    'Home'    => '<!-- wp:paragraph --><p>Welcome to our new site.</p><!-- /wp:paragraph -->',
    'About'   => '<!-- wp:paragraph --><p>Tell visitors who you are.</p><!-- /wp:paragraph -->',
    'Contact' => '<!-- wp:paragraph --><p>How to reach us.</p><!-- /wp:paragraph -->',
);
$wpide_front_page = 'Home'; // One of the titles above, or ''.

add_action( 'wp_initialize_site', function ( $site, $args ) use ( $wpide_pages, $wpide_front_page ) {
    switch_to_blog( $site->blog_id );

    $author = ! empty( $args['user_id'] ) ? (int) $args['user_id'] : get_current_user_id();

    foreach ( $wpide_pages as $title => $content ) {
        $id = wp_insert_post( array(
            'post_type'    => 'page',
            'post_status'  => 'publish',
            'post_title'   => $title,
            'post_content' => $content,
            'post_author'  => $author,
        ) );

        if ( $id && ! is_wp_error( $id ) && $title === $wpide_front_page ) {
            update_option( 'show_on_front', 'page' );
            update_option( 'page_on_front', $id );
        }
    }

    restore_current_blog();
}, 210, 2 );

Notes

Edit $wpide_pages; set $wpide_front_page to one of the titles or leave it empty to keep the latest-posts homepage.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.