How to change the URL of a WordPress site using wp-cli

What is wp-cli?

wp-cli is a tool for performing WordPress administration tasks from the command line. It allows you to manipulate site settings and data without using plugins or dashboards.

How to change the URL of your site

When changing the URL of a WordPress site, especially when migrating sites or changing domains, you need to change the URL in the database. wp-cli’s search-replace command makes this easy to do.

wp search-replace 'https://before.com' 'https://after.com'

The above command will replace the URL ‘https://before.com’ in the database with ‘https://after.com’.

Notes.

Since this operation directly modifies data in the database, it is always recommended to back up the database before executing it. Also, the search-replace command has various options, so please refer to the official documentation and select the appropriate option before use.

Conclusion

Using wp-cli, you can easily and efficiently perform a variety of administrative tasks, such as changing the URL of a WordPress site. However, database operations need to be performed carefully, so please work with great care.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top