Search and Replace
In MyKinsta, you can find a handy tool for doing a search and replace on your site’s content without having to install a plugin, install a script, or use the command line.
Note: When a search and replace is performed, we automatically create a system-generated backup in MyKinsta that can be restored if needed (WordPress Sites > sitename > Backups> System generated).
How to use the search and replace tool in MyKinsta
To locate this tool, log in to MyKinsta, click on WordPress Sites in the left sidebar, and click on the name of the website you want to run the search and replace on:
Click on the Tools tab, look for or scroll to the Search and replace section, and click Search and replace.
There are a number of different operations you can use this tool for. In this example, we’ll change some URLs that use “http” to ones using “https” in the database.
In the search field, enter the value you want to look for in the database, and hit Search. The search and replace tool will display the number of occurrences for the given string:
To search and replace, check the Replace box and enter the new text, URL, or other value in the Replace with field:
We recommend leaving the Clear cache when ready box checked to automatically purge your site’s cache after the search and replace process. That way, visitors will see the updated version of your website right away. Then, click the Replace button.
After the WordPress search and replace is complete, you’ll see a confirmation dialog showing the number of replacements that were processed. When you’re done, click Cancel or the X in the upper right corner of the modal/pop-up to exit the tool. That’s it!
Troubleshooting
When doing a search and replace, there are a couple of errors that may occur that will need some work on your part (or your developer) to resolve. If the fixes shown below do not resolve the issue or if you aren’t comfortable working with WP-CLI, we recommend working with a developer.
Tips and notes
- We recommend making a backup or exporting a copy of the database before running search-replace and making changes to your database.
- The WP-CLI
export
command can be used to export a copy of your database. - Running the WP-CLI search-replace command with the
--dry-run
flag first can help you get a better understanding of what will be changed before actually making any changes. - If errors appear in a search and replace that’s part of pushing staging to live, the push to live will not complete. In this case, to push staging to live, you’ll need to do one of the following:
- Resolve any issues in the staging environment’s database before pushing to live.
- Push staging to live without the Run Search & Replace option checked and perform the search and replace manually after the push completes.
Data too long
This error happens when trying to update a column with a string longer than the value allowed and will look something like:
Data too long for column ‘guid’ at row 1
To work around or fix this, you can try one of the following:
- Run a search-replace with WP-CLI and skip the affected column with the
--skip-columns
flag (e.g.--skip-columns=guid
). - Work with a developer to alter the column and increase the length allowed for the value.
Skipping an uninitialized class
This error usually happens when search and replace encounters an object it needs to load the class for in order to interpret the object, but the plugin or theme the class comes from cannot be loaded correctly. It will look something like:
Skipping an uninitialized class “Some_PHP_Class”, replacements can not be completed.
To work around this error, you can try running a search-replace with WP-CLI. If that fails, try the search-replace with WP-CLI again and add the --skip-plugins --skip-themes
flags to the command.
Tips and examples
Now that we know how to use the search and replace tool, let’s go over some tips and examples.
Tips
- As also noted above, searching is case sensitive, so searching for “WordPress” is different from searching for “wordpress.”
- When replacing URLs, best practice is to either include the full URL, including the protocol (http:// or https://), or at least the leading forward slash before the domain (e.g. /example.com). This prevents unintentionally changing the domain of email addresses.
- You can search and replace entire sentences, including spaces and punctuation.
- For custom site configurations like Bedrock, or in the case of a plugin or theme error, the search and replace tool may not be able to complete. For these situations, we recommend trying the WP-CLI search-replace command with the
--skip-plugins
and/or--skip-themes
flags as needed. - Some plugins and/or themes may have their own search and replace tools that will need to be used due to the way they save information in the database. A few popular examples are:
- BeTheme Muffin Content Builder
- Slider Revolution Domain Switch AddOn (older versions of this plugin may have a Replace URL tool in Slider Settings for each slider).
- OptimizePress
- If your plugin or theme has its own built-in cache, you’ll need to clear that cache after doing a search and replace. Some popular examples are:
- Speaking of cache, if your search and replace doesn’t seem to have updated your site, you may have additional caching besides the server cache handled by Kinsta. You’ll want to make sure you clear all cache in this order:
- Clear any built-in theme or plugin cache.
- Clear site/server cache (yes, clear this again if you cleared any theme or plugin cache).
- Clear browser cache.
Examples
Be sure to replace the example domains as needed.
Replace www.www.domain.com with www.domain.com
This can happen if you already had some instances of www.domain.com in your site’s content, then switched the primary domain from domain.com to www.domain.com in MyKinsta, and checked the box to Run search and replace after change.
Search: /www.www.domain.com
Replace with: /www.domain.com
Replace email address domain only
Maybe you want to use a shorter version of your domain for email sending and receiving or, for some other reason, need to replace the domain of email addresses only without affecting any other instances of the domain (e.g. in image URLs or links).
Search: @olddomain.com
Replace with: @newdomain.com
Replace http URLs with https URLs
While you can redirect HTTP to HTTPS in MyKinsta for your primary domain, you may want to update all URLs in your content as well, or there may be other URLs besides the primary domain you want to change.
Search: http://domain.com
Replace with: https://domain.com
Replace custom domain with temporary domain
If you want to replace one domain with another in your site’s database without affecting email addresses, here’s how. Note the leading forward slash (/) and be sure to replace olddomain.com and newdomain.com with your old and new domains respectively.
Search: /olddomain.com
Replace: /newdomain.com