WordPress ‘theme directory does not exist’

I’ve been stuck for a few hours trying to figure out why one of the websites I’m currently working on for a client wasn’t working.  I was getting the error below whenever I tried to access the theme customiser…

The theme directory “dark” does not exist.

Now to be fair, this is correct, the theme directory “dark” doesn’t exist in this installation.  But my question was, why is WordPress complaining about this?

I  created a “dark” folder in the themes folder and copied in a child theme which used the selected theme as the parent, and this allowed me to get into the admin dashboard.

Now, to figure out, which took a lot of Googling, and very little success.  Nothing people were suggesting seemed to work at all, or simply didn’t apply.  I was pulling my hair out.  And a thought occurred to me…

To cut a long story short, it turned out that when I added the site theme switcher (that light/dark toggle on the right, unless you’re on a mobile and then it’s at the bottom) I went for the rather generic cookie name “theme”, and it also turns out that the WordPress theme customiser uses this cookie as well.

So, lesson learned, use specific cookie names, even if you’re building your own website, because you never know when a conflict will arise.  And “riklewis_theme” is a lot less likely to collide than simply “theme”.

This is fixed now, but if you’re a fan of the dark theme (like me) you may have seen this revert back to light.  Please be assured this is a one off and normal (dark) service will be resumed if you toggle the theme back.