The insert_blog() WordPress PHP function stores basic site information in the blogs table and returns the new blog’s ID.
Usage
$new_blog_id = insert_blog( $domain, $path, $site_id );
Parameters
- $domain (string) – The domain of the new site.
- $path (string) – The path of the new site.
- $site_id (int) – The site ID. Set this value to 1 unless you’re running a multi-network install.
More information
See WordPress Developer Resources: insert_blog()
Examples
Creating a new blog
This example creates a new blog with the specified domain, path, and site ID.
$domain = 'example.com'; $path = '/'; $site_id = 1; $new_blog_id = insert_blog( $domain, $path, $site_id );
Creating a blog on a subdomain
This example creates a new blog on a subdomain.
$domain = 'subdomain.example.com'; $path = '/'; $site_id = 1; $new_blog_id = insert_blog( $domain, $path, $site_id );
Creating a blog on a subdirectory
This example creates a new blog in a subdirectory.
$domain = 'example.com'; $path = '/new-blog/'; $site_id = 1; $new_blog_id = insert_blog( $domain, $path, $site_id );
Creating a new blog on a multi-network install
This example creates a new blog on a multi-network WordPress installation.
$domain = 'example.com'; $path = '/'; $site_id = 2; $new_blog_id = insert_blog( $domain, $path, $site_id );
Creating a new blog with a custom path and domain
This example creates a new blog with a custom domain and path.
$domain = 'customdomain.com'; $path = '/custom-path/'; $site_id = 1; $new_blog_id = insert_blog( $domain, $path, $site_id );