Changing the WordPress Home URL and Site URL is sometimes necessary when moving your site to a new domain, transferring your WordPress installation to a different directory, or resolving specific site issues. In WordPress, the Home URL refers to the main page of your site (the URL visitors see), while the Site URL is the location of your WordPress core files. Ensuring these URLs are configured correctly is essential for smooth navigation and functionality.
Here is an extended guide on various methods to change the WordPress Home URL and Site URL safely and efficiently:
1. Change WordPress Home URL and Site URL in the Admin Dashboard
If you can access your WordPress admin dashboard, this is the simplest way to update your URLs.
Steps to Update via the WordPress Dashboard:
Login to Your WordPress Dashboard:
Navigate to https://yourwebsite.com/wp-admin and log in with your admin credentials.
Go to Settings > General:
In the WordPress dashboard, go to Settings > General.
Update Site Address (URL) and WordPress Address (URL):
Locate the fields labeled WordPress Address (URL) and Site Address (URL).
Update both fields to the new URLs. For example, if you’re moving from http://example.com to https://newsite.com, replace the old URLs with the new domain.
4. Save Changes:
- Scroll down and click Save Changes. WordPress will automatically update your URLs.
5. Verify the Change:
- After saving, your WordPress site should reload with the updated URLs. Test the site by visiting both the homepage and a few internal pages to ensure everything is working.
Note: If you are moving from HTTP to HTTPS, updating these URLs is a necessary part of enabling SSL on your site.
2. Change URLs in the wp-config.php File
If you are unable to access the admin dashboard, you can define the Home and Site URL directly in the wp-config.php file.
Steps to Update via wp-config.php:
Access the WordPress Installation Directory:
Use an FTP client or file manager (like cPanel’s File Manager) to access your site’s root directory, where WordPress is installed. Look for the wp-config.php file.
2. Edit the wp-config.php File:
Open the wp-config.php file and add the following lines of code above the line that says /* That’s all, stop editing! Happy blogging. */:
Replace https://yournewdomain.com with the new URL you want to set.
Save and Upload the File:
Save the changes and upload the modified file to your server, overwriting the existing wp-config.php file if prompted.
Clear Browser Cache and Test:
Clear your browser’s cache and visit your website to confirm that the changes have taken effect.
Note: Adding these lines in wp-config.php will override any settings in the WordPress admin dashboard, making them uneditable there as long as they’re in wp-config.php.
3. Change URLs via the Database Using phpMyAdmin
If neither the admin dashboard nor wp-config.php is accessible, you can manually update the URLs in the database.
Steps to Update via phpMyAdmin:
Access phpMyAdmin:
Log into your hosting control panel (such as cPanel) and locate phpMyAdmin under the Databases section.
2. Select Your WordPress Database:
- In phpMyAdmin, select the database used by your WordPress site. You can find the database name in wp-config.php in the DB_NAME field.
3. Locate the wp_options Table:
In the database, look for the table named wp_options (your prefix may vary, such as wp123_options).
4. Edit the siteurl and home Values:
Find the siteurl and home rows in the option_name column.
Click Edit next to each entry and update the URL in the option_value field with your new domain (e.g., https://yournewdomain.com).
Click Go to save each change.
5. Clear Browser Cache and Test:
After updating, clear your browser’s cache and visit your website to ensure the URLs are working correctly.
Caution: Directly editing the database is powerful but risky. Be careful not to change other fields, and consider creating a backup of your database before making changes.
4. Use WP-CLI to Change Home URL and Site URL
If you have SSH access and are comfortable using the command line, you can use WP-CLI to update the Home URL and Site URL quickly.
Steps to Update URLs with WP-CLI:
Access Your Server via SSH:
Connect to your server via SSH and navigate to your WordPress installation directory.
Run WP-CLI Commands to Update URLs:
Use the following commands to update the URLs:
- Replace https://yournewdomain.com with your new URL.
3. Verify the Change:
Once completed, visit your website to verify the new URLs are working correctly.
5. Use a Plugin to Change URLs
If you prefer a plugin-based approach or want to avoid manual changes, there are plugins that simplify updating the Home and Site URLs.
Steps to Use a Plugin:
Install and Activate the Plugin:
In your WordPress dashboard, go to Plugins > Add New and search for plugins like Better Search Replace or Velvet Blues Update URLs.
Install and activate the plugin of your choice.
Update URLs Using the Plugin:
Go to the plugin’s settings page and enter your old and new URLs.
Follow the plugin’s instructions to replace URLs throughout your site.
Clear Cache and Verify:
After updating, clear any website cache (if you have a caching plugin) and verify that your site is functioning as expected.
6. Troubleshoot Common Issues After Changing URLs
After changing your WordPress URLs, it’s essential to check for common issues that may arise:
Broken Links or Images: Some links or images may still point to the old URL. Use a plugin like Better Search Replace to replace instances of the old URL with the new one in your database.
Mixed Content Warnings (for HTTPS): If you switched to HTTPS, some resources (like images or scripts) may still load over HTTP, resulting in mixed content warnings. Use a plugin like Really Simple SSL to fix mixed content issues.
Permalink Structure Issues: If pages return a “404 Not Found” error, go to Settings > Permalinks in your dashboard and save the settings to refresh the permalinks.
Clear Cache: If your site uses a caching plugin or a Content Delivery Network (CDN), clear the cache after updating URLs to ensure that changes are applied across all cached resources.
Updating your WordPress Home URL and Site URL can be done through several methods, depending on your access level and preferences:
Use the WordPress Dashboard for a straightforward approach.
Modify the wp-config.php file if the dashboard is inaccessible.
Edit the Database via phpMyAdmin for direct control.
Leverage WP-CLI for quick command-line updates.
Use a Plugin to avoid manual configurations.
Making sure your URLs are correctly configured keeps your WordPress site accessible, secure, and error-free. Follow these steps to make smooth and seamless URL changes, and troubleshoot any issues that might arise for optimal site performance.