Fixing COOKIE_DOMAIN for mapped domains on multisite

Today I learned the hard way that WordPress multisite doesn’t quite support domain mapping out of the box the way I expect it to.

I’m working on a website-as-a-service product called ToothPress (more on that at some point in the future). On a paid plan, ToothPress customers will be able to map their custom domain. My dad is my first beta user, so I changed his domain from milwaukiefamilydentistry.toothpress.com to milwaukiefamilydentistry.com:

2016-07-07 at 10.35 AM

Then, I went to log into his dashboard:

2016-07-07 at 10.36 AM

Uh oh, what’s going on?!

As it turns out, WordPress doesn’t magically handle setting the correct COOKIE_DOMAIN. You’ll need to take care of this yourself:

Et voila!

 

6 Comments

Austin "TheFrosty" Passy July 18, 2016 Reply

This seems like the same thing as defining the COOKIE_DOMAIN constant in `wp-config`, no?

`define(‘COOKIE_DOMAIN’, $_SERVER[‘HTTP_HOST’]);`

Daniel Bachhuber July 18, 2016 Reply

Not quite. In the example you’ve provided, the cookie domain would be dynamic for subdomains of the primary network domain, which isn’t what I want.

Chris October 12, 2018 Reply

Where do you add this? In the functions.php file?

Daniel Bachhuber October 13, 2018 Reply

It would need to be loaded much earlier than that, in an mu plugin.

Toby September 12, 2021 Reply

I can’t thank you enough for this fix. I spent hours trying to fix my secondary site once it was mapped to a domain and nothing worked . . . until this. I really appreciate it.

Leave a Reply