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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.