If you’ve encountered the frustrating issue of your WordPress pages reverting to localhost after updating the URLs in phpMyAdmin, don’t worry—this guide will walk you through the steps to fix it. This problem often occurs when site URLs are improperly configured or cached, but it can be resolved with a few adjustments.
1. Update Site URL in the WordPress Database
The first step is to verify and update your site URL directly in the WordPress database.
- Log in to your phpMyAdmin.
- Select your database from the left-hand panel.
- Locate and open the wp_options table (your prefix may vary, e.g.,
wp123_options
). - Search for the following rows:
- siteurl
- home
- Replace their values with your actual site URL, such as:
http://yourdomain.com
- Click Save to apply the changes.
2. Check wp-config.php for Hardcoded URLs
Next, review your wp-config.php
file for any hardcoded URLs that may override the database settings.
- Access your website files using FTP or a file manager in cPanel.
- Locate and edit the wp-config.php file.
- Look for the following lines:
define('WP_HOME', 'http://yourdomain.com'); define('WP_SITEURL', 'http://yourdomain.com');
- If these lines contain localhost, update them to your live site URL or comment them out entirely.
- Save the file and test your site.
3. Regenerate Permalinks
To ensure your WordPress site generates correct URLs, reset your permalink structure.
- Log in to your WordPress dashboard.
- Go to Settings → Permalinks.
- Select your desired permalink structure (or keep the current one).
- Click Save Changes to regenerate the permalink rules.
4. Clear Cache and CDN Settings
If cached data is redirecting your site to localhost, clear the cache:
- Browser cache (Ctrl + Shift + R).
- WordPress caching plugin cache (e.g., WP Rocket or W3 Total Cache).
- CDN cache if you use a Content Delivery Network like Cloudflare.
5. Search and Replace Old URLs in the Database
Sometimes, leftover localhost references remain in the database. Use the Better Search Replace plugin to fix them.
- Install and activate the plugin.
- Go to Tools → Better Search Replace.
- Search for:
http://localhost/yourwebsite
Replace with:
http://yourdomain.com
- Run the replacement and verify the changes.
6. Check Theme and Plugin Files for Hardcoded URLs
Themes and plugins may contain hardcoded URLs pointing to localhost.
- Use a text editor or an FTP client to search for “localhost” in your theme and plugin files.
- Update any references to your live site URL.
7. Ensure SSL and HTTPS Settings Are Correct
If your site uses HTTPS, ensure all URLs in the database and settings are updated to https:// instead of http://.
- Update WordPress and Site Address URLs under Settings → General.
- Use a plugin like Really Simple SSL to handle HTTPS migration automatically.
8. Verify DNS and Hosting Configurations
Double-check your domain’s DNS settings and hosting configurations:
- Ensure your A record or CNAME points to the correct server IP.
- Confirm that your hosting provider is using the right document root for your domain.
9. Flush DNS Cache on Your Computer
Sometimes the issue is local DNS caching. Flush the DNS cache to resolve this.
- Windows:
ipconfig /flushdns
- MacOS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
10. Contact Your Hosting Provider
If none of these steps work, reach out to your hosting provider. They can help check for server-side caching, DNS misconfigurations, or other hidden issues.
Final Thoughts
By following these steps, you should be able to resolve the issue of WordPress pages reverting to localhost. Always back up your database and files before making changes, and test your site thoroughly after each fix. If problems persist, professional WordPress support can assist in diagnosing and repairing the issue.
Let us know in the comments if this guide helped you, or share any additional solutions you’ve discovered!