How to Change the Primary Domain in WordPress

How to Change the Primary Domain in WordPress

When you migrate your site to a new domain or need WordPress to respond under a different address, pointing the domain at the hosting level isn't enough: you must also tell WordPress what its primary address is. If you only make the change on the server and skip this step, it's common to run into:

  • Broken images and files.
  • Internal links that still point to the old domain.
  • Redirect loops when trying to access the site.
  • An inaccessible admin panel (wp-admin).

This guide shows you how to update the primary domain directly from WordPress's internal settings, as well as the steps needed for the entire site to work correctly under the new domain.


Before you begin

Keep these points in mind before making the change:

  • The new domain must already be pointing to your WordPress installation. This manual covers only the WordPress-level configuration. Linking the domain on the server (DNS, primary or addon domain in cPanel) is a separate process; if you need help with that part, you can request it through a support ticket.
  • Make a full backup (files + database) before modifying any value.
  • Have your credentials ready for both the WordPress admin panel and your cPanel account.

Which addresses does WordPress control?

Within WordPress there are two key addresses that define your site's domain:

  • WordPress Address (URL) — stored as siteurl: indicates where the WordPress core files are located.
  • Site Address (URL) — stored as home: the address visitors type to reach your page.

In most installations, both addresses point to the same domain and must be updated together when changing the primary domain.


Method 1: From the admin dashboard (Settings → General)

This is the simplest and recommended method when you still have access to wp-admin.

1. Log in to WordPress

Access your dashboard at https://yourdomain.mx/wp-admin with your username and password.

2. Open the general settings

In the sidebar menu, go to Settings → General.

3. Update the addresses

Edit the two fields so they reflect your new domain:

4. Save the changes

Scroll to the bottom of the page and click Save Changes. WordPress will log you out and you'll need to log back in using the new domain.

Note: If these fields appear grayed out or can't be edited, it means the addresses are defined in the wp-config.php file. In that case, use Method 2.


Method 2: Editing the wp-config.php file

Useful when the dashboard fields are locked or you prefer to set the addresses via code.

1. Log in to cPanel

Access your account at https://my.webzi.mx.

2. Open the File Manager

Go to File Manager and navigate to the folder where WordPress is installed (usually public_html).

3. Edit the wp-config.php file

  1. Locate the wp-config.php file.
  2. Right-click on it and select Edit.
  3. Add the following lines:
  1. define('WP_HOME', 'https://newdomain.mx');
  2. define('WP_SITEURL', 'https://newdomain.mx');
  1. Save the changes.

Note: As long as these lines exist, the Settings → General fields will remain locked, since the file takes priority over the database.


Method 3: From the database (phpMyAdmin)

Recommended as a recovery method when you've lost access to the dashboard (for example, a redirect loop after an incorrect change).

1. Open phpMyAdmin

From cPanel, go to the Databases → phpMyAdmin section.

2. Select your site's database

In the left panel, choose the database that corresponds to your WordPress installation.

3. Edit the options table

  1. Open the wp_options table. The wp_ prefix may vary depending on your installation (for example, wpab_options).
  2. Locate the rows whose option_name is siteurl and home.
  3. Edit each one and replace the option_value with your new domain: https://newdomain.mx
  4. Save each change.

Essential step: update the old URLs in your content

Changing siteurl and home only modifies the primary address, but it does not replace the thousands of references to the old domain that remain within your content: internal links, image paths, plugin settings, and theme data. That's why a bulk URL replacement is necessary.

Install a free plugin such as Better Search Replace, which replaces URLs safely even within serialized data:

  1. Go to Tools → Better Search Replace.
  2. In the Search for field, enter the old domain: https://olddomain.mx
  3. In the Replace with field, enter the new one: https://newdomain.mx
  4. Select all tables.
  5. Run a dry run first to review the results and, if everything is correct, uncheck that box and run the actual replacement.

Note: Avoid running a direct replacement with SQL queries (REPLACE/UPDATE) across the entire database, as it can corrupt WordPress's serialized data. Always use a tool that respects serialization.

Alternative for advanced users (WP-CLI)

If your account has SSH access and WP-CLI, you can do it from the terminal:


Once the domain has been updated, make these final adjustments:

  • Re-save the permalinks. Go to Settings → Permalinks and click Save Changes (without modifying anything) to regenerate the .htaccess rules.
  • Clear all caches: the caching plugin, the server, your CDN, and the browser.
  • Check your page builder. If you use Elementor, URLs are stored separately; go to Elementor → Tools → Replace URL and replace the old domain with the new one.
  • Make sure everything loads over HTTPS to avoid mixed content errors.

Recommendations

  • Always make a backup before editing files or the database.
  • If possible, test the change in a staging environment before applying it in production.
  • Keep the same protocol (https://) across all addresses to avoid inconsistencies.
  • After the change, update your external tools (Google Search Console, sitemap, integrations, and saved logins) with the new domain.

At Webzi, we're committed to keeping your services running smoothly. If you have questions about this procedure or need help carrying it out, don't hesitate to contact us.

    • Related Articles

    • How to fix WordPress memory limit errors

      Sometimes when installing or using themes and plugins in WordPress, you might run into errors related to the memory limit assigned to PHP. Some common messages include: Allowed memory size of xxx bytes exhausted... Fatal error: Out of memory... These ...
    • How to Configure WP Super Cache Correctly

      WP Super Cache is one of the most efficient caching plugins for WordPress. If your site loads slowly or visitors see outdated content, a proper configuration can fix it. This guide shows you how to set it up correctly. When Do You Need to Adjust WP ...
    • How to Change DNS Servers on Windows and macOS – Step-by-Step Guide

      DNS (Domain Name System) servers are responsible for translating website names (like www.webzi.mx) into IP addresses that computers can understand. Your internet provider assigns DNS servers automatically, but you can change them manually to get ...
    • How to Connect Your Domain to Wix

      If you built your website on Wix and want to use your own domain (for example yourdomain.com), you need to configure your domain's DNS to point to Wix's servers. There are two methods to do this: Method What does it do? Keeps email at Webzi? Option ...
    • What Is WP Accelerate and How to Configure It?

      WP Accelerate is a plugin designed for WordPress that includes a set of optimizations designed to improve the performance of WordPress sites hosted in environments with cPanel and CloudLinux. It integrates various techniques and tools that speed up ...