Using WordPress ‘create_empty_blog()’ PHP function

The create_empty_blog() WordPress PHP function is used to create a new, empty blog. This function will need the domain, path, and title of the new blog as input. Optionally, it also takes a site ID, which defaults to 1 if not provided.

Usage

To use the create_empty_blog() function, you can follow the basic structure below:

create_empty_blog( $domain, $path, $weblog_title, $site_id );

For instance, if you want to create a blog with the domain “myblog.com”, path “/blog/”, title “My First Blog”, and site id 2, you can use the function like this:

create_empty_blog( "myblog.com", "/blog/", "My First Blog", 2 );

Parameters

  • $domain (string) – Required. The domain of the new blog.
  • $path (string) – Required. The path of the new blog.
  • $weblog_title (string) – Required. The title of the new blog.
  • $site_id (int) – Optional. The ID of the site. Defaults to 1 if not provided.

More information

See WordPress Developer Resources: create_empty_blog

This function has been implemented in WordPress since version 3.0.0.

Examples

Create a New Blog

In this example, we will create a new blog with the domain “myblog.com”, path “/blog/”, and title “My First Blog”. We will not specify a site ID, so it will default to 1.

create_empty_blog( "myblog.com", "/blog/", "My First Blog" );

Create a New Blog with Specified Site ID

In this example, we create a new blog with the same details as in Example 1, but we also specify a site ID of 2.

create_empty_blog( "myblog.com", "/blog/", "My First Blog", 2 );

Create a New Blog with a Different Path

In this example, we create a new blog with a different path “/newblog/”.

create_empty_blog( "myblog.com", "/newblog/", "My New Blog" );

Create a New Blog with a Different Domain

In this example, we create a new blog with a different domain “yourblog.com”.

create_empty_blog( "yourblog.com", "/blog/", "Your First Blog" );

Create a New Blog with a Different Title

In this example, we create a new blog with a different title “My Second Blog”.

create_empty_blog( "myblog.com", "/blog/", "My Second Blog" );