Title: domain_exists
Published: April 25, 2014
Last modified: August 20, 2026

---

# domain_exists( string $domain, string $path, int $network_id = 1 ): int|null

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#changelog)

Checks whether a site name is already taken.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#description)󠁿

The name is the site’s subdomain or the site’s subdirectory path depending on the
network settings.

Used during the new site registration process to ensure that each site name is unique.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#parameters)󠁿

 `$domain`stringrequired

The domain to be checked.

`$path`stringrequired

The path to be checked.

`$network_id`intoptional

Network ID. Only relevant on multi-network installations.

Default:`1`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#return)󠁿

 int|null The site ID if the site name exists, null otherwise.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#source)󠁿

    ```php
    function domain_exists( $domain, $path, $network_id = 1 ) {
    	$path   = trailingslashit( $path );
    	$args   = array(
    		'network_id'             => $network_id,
    		'domain'                 => $domain,
    		'path'                   => $path,
    		'fields'                 => 'ids',
    		'number'                 => 1,
    		'update_site_meta_cache' => false,
    	);
    	$result = get_sites( $args );
    	$result = array_shift( $result );

    	/**
    	 * Filters whether a site name is taken.
    	 *
    	 * The name is the site's subdomain or the site's subdirectory
    	 * path depending on the network settings.
    	 *
    	 * @since 3.5.0
    	 *
    	 * @param int|null $result     The site ID if the site name exists, null otherwise.
    	 * @param string   $domain     Domain to be checked.
    	 * @param string   $path       Path to be checked.
    	 * @param int      $network_id Network ID. Only relevant on multi-network installations.
    	 */
    	return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/ms-functions.php#L1609)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/ms-functions.php#L1609-L1636)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#hooks)󠁿

 [apply_filters( ‘domain_exists’, int|null $result, string $domain, string $path, int $network_id )](https://developer.wordpress.org/reference/hooks/domain_exists/)

Filters whether a site name is taken.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#related)󠁿

| Uses | Description | 
| [get_sites()](https://developer.wordpress.org/reference/functions/get_sites/)`wp-includes/ms-site.php` |

Retrieves a list of sites matching requested arguments.

  | 
| [trailingslashit()](https://developer.wordpress.org/reference/functions/trailingslashit/)`wp-includes/formatting.php` |

Appends a trailing slash.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#)

| Used by | Description | 
| [wp_validate_site_data()](https://developer.wordpress.org/reference/functions/wp_validate_site_data/)`wp-includes/ms-site.php` |

Validates data for a site prior to inserting or updating in the database.

  | 
| [wpmu_create_blog()](https://developer.wordpress.org/reference/functions/wpmu_create_blog/)`wp-includes/ms-functions.php` |

Creates a site.

  | 
| [wpmu_validate_blog_signup()](https://developer.wordpress.org/reference/functions/wpmu_validate_blog_signup/)`wp-includes/ms-functions.php` |

Processes new site registrations.

  | 
| [create_empty_blog()](https://developer.wordpress.org/reference/functions/create_empty_blog/)`wp-includes/ms-deprecated.php` |

Create an empty blog.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/domain_exists/?output_format=md#changelog)󠁿

| Version | Description | 
| [MU (3.0.0)](https://developer.wordpress.org/reference/since/mu.3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fdomain_exists%2F)
before being able to contribute a note or feedback.