Family Encyclopedia >> Electronics

How to add / remove default pages in WordPress Multisite

When you are running a WordPress multisite, every time a new site is created, WordPress automatically adds a sample page to the new site. Recently, one of our users asked us if it was possible to remove the default sample page and add their own default pages. In this article, we will show you how to add/remove default pages in WordPress multisite.

Why add your own default pages in WordPress Multisite?

There can be many reasons to replace the default sample page with your own. For example, you might want to add a page that tells users what to do next.

The default sample page generated by WordPress is a bit boring. Maybe you would like to add something clever and clever?

Lastly, you can use the default page to tell users what to do and what not to do in your multisite network.

Add / remove default pages in WordPress

Simply add this code to your main site's functions.php file or to a site-specific plugin.

 add_action ('wpmu_new_blog', 'wpb_create_my_pages', 10, 2); función wpb_create_my_pages ($ blog_id, $ user_id) switch_to_blog ($ blog_id); // crear nueva página $ page_id = wp_insert_post (array ('post_title' => 'About', 'post_name' => 'about', 'post_content' => 'Esta es una página sobre. Siéntase libre de editar o eliminar esta página . ',' post_status '=>' publish ',' post_author '=> $ user_id, // o "1" (super-admin?)' post_type '=>' page ',' menu_order '=> 1,' comment_status '=>' closed ',' ping_status '=>' closed ',)); // Busque y elimine la 'Página de muestra' predeterminada de WP $ defaultPage = get_page_by_title ('Página de muestra'); wp_delete_post ($ defaultPage-> ID); restore_current_blog (); 

The first part of this code inserts a new WordPress page titled 'About' every time a new site is created on your multisite network. The second part of the code finds and removes the default WordPress Example Page .

We hope this article helped you to add/remove default pages in WordPress multisite network.

If you liked this article, please join us on Google+ and Twitter. You can also subscribe to our YouTube channel for more WordPress video tutorials.