Using WordPress ‘ms_cookie_constants()’ PHP function

The ms_cookie_constants() WordPress PHP function defines Multisite cookie constants.

Usage

ms_cookie_constants();

Parameters

  • None

More information

See WordPress Developer Resources: ms_cookie_constants()

Examples

This code snippet calls the ms_cookie_constants() function to define the Multisite cookie constants.

// Call the ms_cookie_constants function
ms_cookie_constants();

Check if Multisite is enabled

This code snippet checks if the Multisite feature is enabled and then calls the ms_cookie_constants() function.

// Check if Multisite is enabled
if (is_multisite()) {
    // Define Multisite cookie constants
    ms_cookie_constants();
}

This code snippet calls the ms_cookie_constants() function and then sets custom cookie constants.

// Define Multisite cookie constants
ms_cookie_constants();

// Set custom cookie constants
define('MY_CUSTOM_COOKIE', 'my_custom_cookie');

This code snippet calls the ms_cookie_constants() function and then sets cookies using the defined constants.

// Define Multisite cookie constants
ms_cookie_constants();

// Set cookies using the defined constants
setcookie(LOGGED_IN_COOKIE, 'logged_in_value', time() + 3600, COOKIEPATH, COOKIE_DOMAIN);

This code snippet calls the ms_cookie_constants() function and then displays the defined cookie constants.

// Define Multisite cookie constants
ms_cookie_constants();

// Display the defined cookie constants
echo 'Cookie Domain: ' . COOKIE_DOMAIN . '<br>';
echo 'Cookie Path: ' . COOKIEPATH . '<br>';
echo 'Site Cookie Path: ' . SITECOOKIEPATH . '<br>';
echo 'Logged in cookie: ' . LOGGED_IN_COOKIE . '<br>';