Title: WP_Network::_set_cookie_domain
Published: December 9, 2015
Last modified: May 20, 2026

---

# WP_Network::_set_cookie_domain()

## In this article

 * [Source](https://developer.wordpress.org/reference/classes/wp_network/_set_cookie_domain/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_network/_set_cookie_domain/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_network/_set_cookie_domain/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_network/_set_cookie_domain/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Sets the cookie domain based on the network domain if one has not been populated.

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

    ```php
    private function _set_cookie_domain() {
    	if ( ! empty( $this->cookie_domain ) ) {
    		return;
    	}
    	$domain              = parse_url( $this->domain, PHP_URL_HOST );
    	$this->cookie_domain = is_string( $domain ) ? $domain : $this->domain;
    	if ( str_starts_with( $this->cookie_domain, 'www.' ) ) {
    		$this->cookie_domain = substr( $this->cookie_domain, 4 );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-network.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-network.php#L306)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-network.php#L306-L315)

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

| Used by | Description | 
| [WP_Network::__construct()](https://developer.wordpress.org/reference/classes/wp_network/__construct/)`wp-includes/class-wp-network.php` |

Creates a new [WP_Network](https://developer.wordpress.org/reference/classes/wp_network/) object.

  |

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

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

## User Contributed Notes

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