Whew – it took me a long time to figure this out.
The problem occurs when you have a different WordPress Address and Site Address in the WordPress settings. The cookie that gets placed to validate your session is in the wrong domain. It has nothing to do with which theme you are using, which plug-ins you’re running, or a messed-up site configuration.
The reason to use different WordPress Address and Site Address setting is because your domain points to a different location than the actual location of your website’s files – ie, your domain is a sub-domain of another domain. So, for example, say your website’s URL is “www.secondarydomain.com”, and it is installed under the “primarydomain” on your web server:
Wordpress Address: https://primarydomain/secondarydomain.com
You don’t want people to see or use this URL – you want them to use the …
Site Address: https://secondarydomain.com
Configuring your settings like that works fine EXCEPT when you want to preview changes when you are customizing a theme. For some reason the session can’t find your login validation cookie and therefore asks you to log in again (and again, and again, etc).
In order to fix this, you need to modify the .htaccess file on the web server for the subdomain.
- On the Permalinks setting page in WordPress click “Save”. This will ensure that the .htaccess file is created. (Permalinks are affected by the WordPress Address / Site Address settings because they are part of the URL component.)
- In many cases WordPress will not be able to write the necessary changes to the .htaccess file. This is for security reasons. At the bottom of the Permalinks page, WordPress will show you the text that needs to be added to your .htaccess file.