Wordpress - Can I set some default pages to be created on every creation of a new blog
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.
use "wpmu_activate_blog" instead of "activate_blog". it worked for me. thanks