Click here or hit escape to close this.

Cookies
WordPress Network: Cookie error when using different domains

Notice: this post is 3 years old, its content may be outdated.

This is a recurring I have with my website: I can’t get my WordPress Network to work properly when using different, unrelated domains.

Both my personal and professional blog (blog.charliemerland.me and blog.caercam.org) from the same WordPress installation, as well as my Themes Demo site (themes.caercam.org). I read a lot about WordPress MU Domain Mapping, spend quite a lot of time reading StackExchange threads; I found a lot of answers, too, but nothing that would work for me. Here’s what I figured out.

Set up

I have three sites in my Network:

  • Blog | CaerCam.org
  • Blog | Charlie MERLAND
  • WordPress Themes

My Domain Mapping options are:

  1. ☑ Remote Login
  2. ☑ Permanent redirect (better for your blogger’s pagerank)
  3. ☐ User domain mapping page
  4. ☑Redirect administration pages to site’s original domain (remote login disabled if this redirect is disabled)
  5. ☑Disable primary domain check. Sites will not redirect to one domain name. May cause duplicate content issues.

And in wp-config.php:

define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUNRISE', 'on');
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'blog.caercam.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('NOBLOGREDIRECT', true);

No matter what changes I try to do, I either:

  • Lose control over at least one site, possibly all of them: “ERROR: Cookies are blocked or not supported” error
  • Cripple at least one site, possibly all of them: all permalinks redirect to the main site

The only I found to make things work is to alter mu /wp-content/sunrise.php file, commenting the Cookie related line:

if ( !defined( 'SUNRISE_LOADED' ) )
	define( 'SUNRISE_LOADED', 1 );

// Comment this
//if ( defined( 'COOKIE_DOMAIN' ) ) {
//	die( 'The constant "COOKIE_DOMAIN" is defined (probably in wp-config.php). Please remove or comment out that define() line.' );
//}

// let the site admin page catch the VHOST == 'no'
$wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
$dm_domain = $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] );

And add the following to wp-config.php:

define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUNRISE', 'on');
define('SUBDOMAIN_INSTALL', true);
define('DOMAIN_CURRENT_SITE', 'blog.caercam.org');
define('PATH_CURRENT_SITE', '/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);
define('NOBLOGREDIRECT', true);

$my_sites = array(
	'blog.caercam.org',
	'themes.caercam.org',
	'blog.charliemerland.me'
);

if ( isset( $_SERVER[ 'SERVER_NAME' ] ) && in_array( $_SERVER[ 'SERVER_NAME' ], $my_sites ) )
	define( 'COOKIE_DOMAIN', $_SERVER[ 'SERVER_NAME' ] );

Yes, that’s not a clean way to proceed, there might be a better solution (think of me when you find it!), but still, it works. This post is as much a reminder to myself in case I broke everything in a few months as it can be a piece of help for someone bumping into the same issue.

Photo: Cookies by Neil Conway