Can I set some default pages to be created on every creation of a new blog

The pages like “about” will be created automatically when a new blog is created. Likewise I need some other pages which should appear automatically when a blog is created under my multisites.

How can I configure the default pages to be created with a new blog under a multisite?

Read More

For ex.: If I have a multisite on example.com. Every blog created under this site should have
Home, About, My store, My address.

Related posts

Leave a Reply

2 comments

  1. I recommend creating a function in your functions.php file that ties to the action hook activate_blog. Use the WordPress functions get_pages() to see if your default pages exist. If they do not, create them with wp_insert_post.

    add_action('activate_blog','my_default_pages');
    
    function my_default_pages(){
        $default_pages = array('About','Home','My Store','My Address');
        $existing_pages = get_pages();
    
        foreach($existing_pages as $page){
            $temp[] = $page->post_title;
            }
    
    
        $pages_to_create = array_diff($default_pages,$temp);
    
        foreach($pages_to_create as $new_page_title){
    
                // Create post object
                $my_post = array();
                $my_post['post_title'] = $new_page_title;
                $my_post['post_content'] = 'This is my '.$new_page_title.' page.';
                $my_post['post_status'] = 'publish';
                $my_post['post_type'] = 'page';
    
    
    
                // Insert the post into the database
                $result = wp_insert_post( $my_post );
    
            }
            }
    

    To test this function on your own site, try setting the hook to wp_head. It will run on each page load and insert the pages that don’t exist, with the content in $my_post[‘post_content’]. *Does the ‘activate_blog’ hook run when blogs are created in a multi-site context? I don’t know.*

    Refer to the codex page for wp_insert_post that I linked to for the complete list of default parameters available.