I finally solved this issue. I’m going to post my answer here so that it can help anyone else who’s stuck with it. I spent an entire day trying to get it rectified.
Things that I tried on a staging site to troubleshoot this issue:
- Disable all plugins
- Change the theme
- Fiddling around various settings on the wordpress site
The problem was that if you open page X, Y before you login then after logging in when you visit X & Y it’ll show that you’re logged out. But other pages would show that you’re still logged in. This observation was critical in reproducing the issue and determining that it’s related to the cache.
Root cause:
I had some rules present in the .htaccess file that were setting the header to cache resources. This was causing a cache issue with the login.
I didn’t add those rules. They were added automatically by SG Optimizer plugin which I installed when I was with the SiteGround host. After migrating hosts and removing the SG Opt. plugin, these lines were still present in the .htaccess file causing the issues.
Once I cleared the .htaccess file my site’s login started working fine.
Next, I installed an actual caching plugin since the functionality had been disabled from the .htaccess file.