A WordPress-centric search engine for devs and theme authors

insert_blog ›

insert_blog ( $domain, $path, $network_id )
Parameters: (3)
  • (string) $domain The domain of the new site.
    Required: Yes
  • (string) $path The path of the new site.
    Required: Yes
  • (int) $network_id Unless you're running a multi-network installation, be sure to set this value to 1.
    Required: Yes
  • (int|false) The ID of the new row
Defined at:
Change Log:
  • MU

Store basic site info in the blogs table.

This function creates a row in the wp_blogs table and returns the new blog's ID. It is the first step in creating a new blog.


function insert_blog( $domain, $path, $network_id ) {
	global $wpdb;

	$path       = trailingslashit( $path );
	$network_id = (int) $network_id;

	$result = $wpdb->insert(
		$wpdb->blogs, array(
			'site_id'    => $network_id,
			'domain'     => $domain,
			'path'       => $path,
			'registered' => current_time( 'mysql' ),
	if ( ! $result ) {
		return false;

	$blog_id = $wpdb->insert_id;
	clean_blog_cache( $blog_id );

	wp_maybe_update_network_site_counts( $network_id );

	return $blog_id;