Using Search and Replace on WordPress and Your Pressable Site
When you set up a site on Pressable, a staging URL is created:
There are a couple of advantages of this staging URL:
- Migrating a site from another host: You can move the files and database and test before changing DNS.
- Cloning a site already on Pressable: Test updates, make changes, etc., without modifying your live site.
When you add a domain to your site, often times the staging URL remains in your database instead of being replaced by the live domain. These will all 301 redirect to the primary domain. However, in these instances you may want to run a search/replace of the staging URL to your live domain. There are a couple of ways to accomplish this:
Warning before doing anything to your Database!
Run a backup of your database before making any changes. If you have a backup of your database and make a mistake, then you can quickly revert to the backup and have the site up and running again.
Click here to learn how to backup your site and Database.
WordPress Plugin: Better Search Replace
When moving your WordPress site to a new domain or server, you will likely run into a need to run a search/replace on the database for everything to work correctly. Fortunately, there are several plugins available for this task. However, all have a different approach to a few key features. This plugin consolidates the best features from these plugins, incorporating the following features into one simple plugin:
- Serialization support for all tables
- The ability to select specific tables
- The ability to run a “dry run” to see how many fields will be updated
- No server requirements aside from a running installation of WordPress
- WordPress Multisite support
WP-CLI / SSH
You can run a search/replace on the database using WP-CLI via SSH. When logged into the site via SSH, use this WP-CLI command to automatically search through all tables in a database to replace one string with another string:
wp search-replace https://oldurl.com https://newurl.com --all-tables
You’ll be required to flush the site cache after running the search-replace command like so
wp cache flush
Contact Pressable Support
If you have tried this plugin and are having issues, or just want Pressable Support to help, please contact us at firstname.lastname@example.org. Please provide the live domain of the site you need help with and we can make this update for you.