You need to make few changes to your website if you own a business. but some modification in website takes a lot of time and efforts whether you can switching the domains, or migrating the website from one to other servers, or uncovering all shortcodes from one website to another much time and efforts are required.
If you ever have worked with Microsoft office word then you might be familiar with the team known as ‘search and replace’. In WordPress, you can build the same effects.
If you are looking to change few things in your website then such kind of functionality can help you in saving a lot of effort and time in hours or days. However such functionality will make your task easier and effective as much as possible.
In this blog post, we will learn about the Search and Replace in WordPress and why it is important in WordPress. Plus we will provide you three simple methods to do it.
Thus you will get familiar with few WordPress plugins that are user-friendly and not require any sort of technical knowledge to work with it. Other than this you will get familiar with some advanced MySQL queries and WP-CLI commands.
In WordPress why do you need to perform search and replace method?
There are so many different screenplays that you will come across and will find the use of search and replace method n WordPress that will help you in simplifying the task.
If you are a beginner or new to the web development field, even to change the URL of your website you will find this method to be more helpful and the most convenient way to save your time.
Some examples that when you need to use the finds and replaces method are while migrating the website from HTTP to HTTPS or while changing the domain completely from one to another.
The search and replace method will seem like the most helpful method to update the references with news throughout your website, broken links, preventing errors, or any other problems.
While moving your complete website from localhost installations then you can also perform a search and replace method or even you can do use this method while migrating your website to a live server from a local website.
This will provide a reference to a server and will add more details to the one you are transferring. However, this will help you in stopping errors and incompatibility.
It is obvious that you miss a single reference when you start running so many URLs i.e. hundreds of URLs manually. The rankings on your search engines can be broken down which will result in a bad user experience. But now you can update thousands of URLs without getting any missed because of the search and replace method.
Whereas there are few plugins that provide so many shortcodes. If you ever want to delete or disable any of that plugin then you have to make sure that the shortcodes you have added using those plugins have been deleted.
Your website’s performance can be damaged badly if you ever failed to delete those related shortcodes. Sometimes it might cause an error too. In this situation search and replace method will be the most helpful thing for you as it will save a lot of work and effort too.
3 different ways to do a search and replace are given below
Every corner of your WordPress database can be affected if you are performing a search and replace method in bulk. You should always create a WordPress database backup to ensure you will not losses any kind of important data of your website.
In different ways, you can do Search and Replace in WordPress. In this blog post, we have added some simple options to perform search and replace with a plugin, with WordPress via command line and issuing MySQL queries.
Integrate WordPress plugin known as Search Regex
If you are a beginner and looking to perform a search and replace method then you must choose to integrate the search regex plugin first. You can say that it is the most dedicated plugin that allows you to change everything from post, WordPress data, custom post types, comments, pages, and plugins to metadata.
You can easily install this plugin from the WordPress dashboard, by selecting the tools and then clicking on search regex you can access this tool. After this add the term that you are looking to search in the search field. You can also add particular content that this tool should search for with the help of the source field.
This plugin will showcase the complete result related to search words without replacing the matched. This will help you to note a specific result that you don’t want to replace.
Thus it will help you to refine the search as per your wish. The match which is not suitable for the thing that you are searching for can be replaced but it will cause an issue, therefore, this can be considered as an important step.
Now you can just choose a term that you want to find and replace. Thus the task of clicking replace button will apply the changes to complete content on your website. You will have to select the three-dot icon for replacing the separate references. Now click on replace row. Hereafter you can click on replace by adding the replacement texts.
By adding a new value in the field of replacing you can replace all positive matches too. After this click on replace all. All identified matches will be updated by using search regex.
Via PhpMyAdmin perform the MySQL Query
Another method to perform the Search and Replace in WordPress is to use PhpMyAdmin. By choosing this method you will be able to update the database of your WordPress website without installing and without learning about the specific plugins.
But you need to be getting familiar with SQL domain-specific language because while performing search and replace via SQL you will need to work with PhyMyAdmin. From your hosting account, you can access phpMyAdmin. Under the databases, you can also select phpMyAdmin if your host is using cPanel.
On the left-hand side of the menu, you will find the option to modify the database. After selecting the database now select the SQL tab.
using SQL you will have to perform the search and replace method. It uses the format given below
update TABLE_NAME set FIELD_NAME= replace(FIELD_NAME, 'Search', 'Replace'); In the example given below, we are searching for "blogging" on WordPress posts. Now every positive search that matched to term blogging will be replaced with "testing" update wp_posts set post_content= replace(post_content, 'blogging', 'testing');
Click on the Go button to run this SQL query. After this, the phpMyAdmin will showcase to you the multiple rows that are modified with this query.
However, the phpMyAdmin also gives the function i.e. Search and Replace in WordPress. By selecting the search tab you will be able to access this in PhpMyAdmin console.
But make in mind that, unlike the search regex plugin, you will not find any other method to see the query demo before running it. Suppose you have replaced the unwanted term then it will affect the content of your website. Ultimately it will affect your customers as they will find irrelevant content.
Using WP-CLI run a wp search-replace command
Using wp-CLI you can execute the search and replace method. In the table, it will search every row of a specific string. thus it will replace all positive result strings with the string you will define.
The following format is used by wp-search-replace command
wp search-replace <'older'> <'newer'> <table>
This command identifies that the older is a first-string that it will search for and the newer is the string that will be replaced instead of older. However, you will have to execute the following command if you want to replace the term grapes with mango in the wp_term table.
wp search-replace 'grapes' 'mango' wp_terms
Using dry-run command
While performing the search and replace function with the help of the command-line make sure you are also performing the dry run. This is a very important step. The following command is given to perform the dry run command.
wp search-replace <'old'> <'new'> <table> --dry-run
This step is very important and recommended if you want to save your website from encountering a new issues.
Conclusion:
The task of modifying thousands of files on a database is a very hectic and time-consuming job. However with the help of the Search and Replace in WordPress you can safeguard your time and efforts as it will help you to change hundreds and thousands of strings just by searching and replacing the string quickly and effectively.
The post How to Perform a Search and Replace in WordPress appeared first on SKT Themes.
0 Commentaires