{"id":7849,"date":"2020-05-31T15:00:26","date_gmt":"2020-05-31T13:00:26","guid":{"rendered":"https:\/\/qodeinteractive.com\/magazine\/?p=7849"},"modified":"2021-04-22T10:33:14","modified_gmt":"2021-04-22T08:33:14","slug":"search-and-replace-wordpress","status":"publish","type":"post","link":"https:\/\/qodeinteractive.com\/magazine\/search-and-replace-wordpress\/","title":{"rendered":"How to Perform a Search and Replace on Your Whole WordPress Site"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]Have you ever wanted to replace a word or phrase across all your posts and pages? Or has your company changed something about its brand and needs that to be reflected on their entire site? On the other hand, if you ever migrate your site from one domain to another, clone from or to a local-hosted environment or add SSL support to your existing website, you will need to change all the URLs as well. Manually going through each and every page or post for edits would be both exhausting and time-consuming. Knowing how to quickly search and replace a word or phrase across your entire WordPress website is incredibly useful. So, we put together this tutorial to show you how to do this in a few straightforward steps:[\/vc_column_text][vc_empty_space height=&#8221;22px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#using-a-plugin\">Using a WordPress plugin<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#running-queries-in-phpMyAdmin\">Running queries in phpMyAdmin<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;5px&#8221;]<ul class=\"qodef-unordered-list-item qodef-toc\">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n            <span class=\"qodef-ul-title-content\"><a href=\"#adding-code-to-the-functions-php-file\">Adding code to the functions.php file<\/a><\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_empty_space height=&#8221;70px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">How to Perform a Search and Replace<\/h2>\n<p>[\/vc_column_text][vc_column_text]There are many ways to search and replace content across your WordPress site but we will only show you a few. Since this is generally the domain of developers and professionals with coding knowledge we have selected a couple of the less advanced methods. You can <strong>choose from them according to your skill level<\/strong>. However, <strong>if you still find yourself lost or unable to follow the steps we suggest you seek professional help<\/strong>. Trying any of these methods may break your website, so please follow the instructions carefully and <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-backup-wordpress-database\/\">make a database backup<\/a> beforehand.[\/vc_column_text][vc_empty_space height=&#8221;72px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\"><a id=\"using-a-plugin\"><\/a>Search and Replace Using a WordPress Plugin<\/h3>\n<p>[\/vc_column_text][vc_column_text]One of the reasons why WordPress is so popular is the sheer number of plugins, free or paid, which you can choose from to get added features. They <strong>allow you to extend the functionalities of your site in almost any area, including find and replace<\/strong>. For this tutorial, we\u2019re going to use the <a href=\"https:\/\/wordpress.org\/plugins\/better-search-replace\/\" target=\"_blank\" rel=\"noopener noreferrer\">Better Search Replace<\/a> plugin. Its features will let us narrow the search by selecting specific database tables and we can even test the search and replace feature before executing it.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Begin by installing the plugin. To do that go to <em>Plugins &gt; Add New<\/em> and search for the Better Search Replace plugin then click on <em>Install Now<\/em>. Activate the plugin afterward.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/1-Better-Search-Replace-plugin.jpg\" class=\"attachment-full size-full\" alt=\"Better Search Replace plugin\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/1-Better-Search-Replace-plugin.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/1-Better-Search-Replace-plugin-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/1-Better-Search-Replace-plugin-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]You will be able to <strong>access the plugin options by going to <em>Tools &gt; Better Search Replace<\/em><\/strong>. When you open it, make sure you\u2019re on the <em>Search\/Replace<\/em> tab. From there you can<strong> type in the phrases or words to Search for and Replace with<\/strong>. You can select which tables to search in and tick different options. After you\u2019ve done that, click on the <em>Run Search\/Replace<\/em> button. If you tick the <em>Run as dry run?<\/em> option, you will <strong>get a list of search results but no changes will be made<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/2-Better-Search-Replace-Tools.jpg\" class=\"attachment-full size-full\" alt=\"Better Search Replace Tools\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/2-Better-Search-Replace-Tools.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/2-Better-Search-Replace-Tools-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/2-Better-Search-Replace-Tools-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;60px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/3-Find-and-Replace-on-Your-Whole-WordPress-Site.jpg\" class=\"attachment-full size-full\" alt=\"Find and Replace on Your Whole WordPress Site\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/3-Find-and-Replace-on-Your-Whole-WordPress-Site.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/3-Find-and-Replace-on-Your-Whole-WordPress-Site-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/3-Find-and-Replace-on-Your-Whole-WordPress-Site-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]If you want to change the database, make sure that this option isn\u2019t ticked. And after you make changes, a notice at the top of the page will appear, showing <strong>how many tables were searched and the number of changes made<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/4-how-many-tables-were-searched-and-the-number-of-changes-made.jpg\" class=\"attachment-full size-full\" alt=\"How many tables were searched\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/4-how-many-tables-were-searched-and-the-number-of-changes-made.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/4-how-many-tables-were-searched-and-the-number-of-changes-made-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/4-how-many-tables-were-searched-and-the-number-of-changes-made-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Before we go further, we need to take a look at a few database tables in more detail.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]During a standard WordPress installation, <strong>12 tables are automatically created inside your database<\/strong>: <em>wp_posts, wp_postmeta, wp_comments, wp_commentmeta, wp_options, wp_users, wp_usermeta, wp_terms, wp_termmeta, wp_term_relationships, wp_term_taxonomy and wp_links<\/em>. If you want to learn in-depth about database tables then you can check out resources like the <a href=\"https:\/\/codex.wordpress.org\/Database_Description\" target=\"_blank\" rel=\"noopener noreferrer\">WordPress Codex<\/a>. And if you have plugins installed, your database could contain additional plugin-related tables. Now, of the original 12 tables, only some are relevant to us now.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>The wp_posts table<\/strong> is probably the most important table in your WordPress database. It contains information about your posts, pages, menu items, attachments, and custom post types. It also contains post ID, content, and type, as well as author ID, date of creation, excerpt, title, comment status (if you enabled post comments), publish status (e.g. \u2018pending\u2019, \u2018publish\u2019 or \u2018private\u2019) and its GUID.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>The wp_comments table<\/strong>, as the name suggests, contains all the comments which were made and information about them. It includes comment content, author of the comment, their email, URL, and IP address, date when the comment was posted and its type (comment, pingback or trackback).[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>The wp_users table<\/strong> contains information about users managing your WordPress website. Among other fields, there are user ID, username and password, user email, and URL.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>The wp_options table<\/strong> contains information about active plugins and their settings, as well as theme settings, widget content, and cache. It contains the name of the plugin setting stored, its value, and if it is autoloaded.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Now we\u2019re going to circle back to our plugin options to explain <strong>what <em>Replace GUIDs?<\/em> means<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>The GUID column is a column inside the <em>wp_posts table<\/em><\/strong>. GUIDs or<strong> Globally Unique Identifiers are constants used when generating RSS feeds<\/strong>. WordPress uses GUIDs to determine if two posts are the same and avoid post duplicates from showing. For example, if you\u2019ve changed the URL, title, or some of the content of an old post, the GUIDs stop it from popping up on the RSS feed as a brand new post. So, changing post GUIDs can cause post duplicates to appear as new posts in your readers&#8217; feed, which can be annoying and lead to them unsubscribing. Unless you are switching domains or working on development sites, we would urge you<strong> not to make any changes to the GUID column<\/strong>.[\/vc_column_text][\/vc_column][\/vc_row][vc_row][vc_column][vc_empty_space height=&#8221;81px&#8221;][vc_separator color=&#8221;custom&#8221; accent_color=&#8221;#f0f0f0&#8243;][vc_empty_space height=&#8221;50px&#8221;][vc_widget_sidebar sidebar_id=&#8221;top-picks-banner&#8221;][vc_empty_space height=&#8221;28px&#8221;][vc_separator color=&#8221;custom&#8221; accent_color=&#8221;#f0f0f0&#8243;][vc_empty_space height=&#8221;82px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\"><a id=\"running-queries-in-phpMyAdmin\"><\/a>Running Queries in phpMyAdmin<\/h3>\n<p>[\/vc_column_text][vc_column_text]Another method of running search and replace across your WordPress website is via queries that affect your database. It\u2019s very effective, but we suggest it for advanced WordPress users only.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To begin,<strong> log in to cPanel and find the phpMyAdmin option<\/strong> within the Databases section.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"378\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/02\/phpMyAdmin.jpg\" class=\"attachment-full size-full\" alt=\"phpMyAdmin\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/02\/phpMyAdmin.jpg 710w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/02\/phpMyAdmin-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/02\/phpMyAdmin-620x330.jpg 620w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]A new window will open, showing all your databases.<strong> From the menu on the left, select the database for the site you want to change<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]However,<strong> if you aren\u2019t sure what your database name is, you can find that out by inspecting the wp-config.php file<\/strong>. To do so, connect to your server using your FTP credentials and navigate to your root WordPress directory (usually called <em>public_html<\/em>). <strong>Locate the wp-config.php file within the directory, right-click it, and select View\/Edit from the dropdown menu<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"378\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/03\/Wp-config-edit.jpg\" class=\"attachment-full size-full\" alt=\"WP Config Edit\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/03\/Wp-config-edit.jpg 710w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/03\/Wp-config-edit-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/03\/Wp-config-edit-620x330.jpg 620w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Look for the piece of code that looks like this:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">define( 'DB_NAME', 'your-database-name' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]and you will find the name of your database.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/5-Find-the-name-of-your-database.jpg\" class=\"attachment-full size-full\" alt=\"Find the name of your database\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/5-Find-the-name-of-your-database.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/5-Find-the-name-of-your-database-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/5-Find-the-name-of-your-database-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]So now that we know which database we\u2019ll be editing, we need to go back to cPanel and phpMyAdmin in order to run our search and replace.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>There are two ways you can do this\u2014manually or automatically<\/strong>. Both methods require you to run an SQL query, the difference lies in the query structure and how you proceed when the results are returned.[\/vc_column_text][vc_empty_space height=&#8221;23px&#8221;]<ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">Manually replacing the words\/phrases<\/span>\n            <\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_column_text]For this method you need to make an SQL query, i.e. search your database for a word\/phrase and manually replace each returned result.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>Example:<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]From phpMyAdmin, <strong>select your database from the menu on the left<\/strong>, and <strong>click on the <em>SQL<\/em> tab<\/strong> in the top menu. In the window below, <strong>insert the SQL query<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Before we proceed, let\u2019s take a look at the query we\u2019re going to use. It is an offshoot of a generic query:<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT * FROM table_name WHERE (field_name LIKE 'your-phrase-with-a-wildcard');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]This query returns all entries from a database table called <em>table_name<\/em> where a column <em>field_name<\/em> contains a pattern called <em>your-phrase-with-a-wildcard<\/em>. Now let\u2019s break down the wildcard phrase.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]SQL supports two wildcard operators which are used in conjunction with <strong>LIKE<\/strong> to describe a pattern you wish to search for. Those are the percent sign (%) and the underscore (_). The percent sign represents zero or more characters, while the underscore represents exactly one character. For example, the phrase <em>%work%<\/em> represents a pattern that has 0 or more characters followed by the word <em>work<\/em>, after which there are also 0 or more characters. Blank spaces are also considered characters. So, querying for the phrase <em>%work%<\/em> will return results that include the word <em>work<\/em> by itself, in a sentence, or a paragraph.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To illustrate, we\u2019re going to look for work in our site posts, so that query looks like:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SELECT * FROM wp_posts WHERE (post_content LIKE '%work%');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]To run the query, press Go. This will return all entries from the <em>wp_posts table<\/em> in our database which contain the word <em>work<\/em> in the <em>post_content<\/em> column.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Run-the-query.jpg\" class=\"attachment-full size-full\" alt=\"Run the query\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Run-the-query.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Run-the-query-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Run-the-query-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]The list of results will be shown underneath the query window. To edit a result, you will need to <strong>click the Edit button within a result<\/strong> row and manually change (i.e. replace) each result.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Click-the-Edit-button.jpg\" class=\"attachment-full size-full\" alt=\"Click the Edit button\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Click-the-Edit-button.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Click-the-Edit-button-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/7-Click-the-Edit-button-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]When you click <em>Edit<\/em>, a new window will open. On the left, locate the<em> post_content<\/em> column and then click on the <em>Value entry<\/em> in it. Find the word\/phrase you were looking for (in our case it is work) and edit it. If you are unable to find it with the naked eye, <strong>you can search for it with CTRL + F<\/strong>. All the matches will be highlighted so you can spot them easily.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/8-Find-the-word-you-were-looking-for.jpg\" class=\"attachment-full size-full\" alt=\"Find the word you were looking for\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/8-Find-the-word-you-were-looking-for.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/8-Find-the-word-you-were-looking-for-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/8-Find-the-word-you-were-looking-for-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]When you\u2019re done, scroll to the end of the page and click Go to save the change.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]If the edit was successful you will get a confirmation message.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/10-Confirmation-message.jpg\" class=\"attachment-full size-full\" alt=\"Confirmation messag\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/10-Confirmation-message.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/10-Confirmation-message-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/10-Confirmation-message-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>You need to repeat this process to edit all the other SQL query results<\/strong>. Making changes manually may be slow-going but it gives you greater control over the edits. If you use this method to run search and replace you can account for context and change all instances of a word\/phrase differently.[\/vc_column_text][vc_empty_space height=&#8221;23px&#8221;]<ul class=\"qodef-unordered-list-item \">\n    <li>\n\t        <div class=\"qodef-ul-title-holder\">\n                        <span class=\"qodef-ul-title\">\n                <span class=\"qodef-ul-title-text\">Automatically replacing the words\/phrases<\/span>\n            <\/span>        <\/div>\n            <\/li>\n<\/ul>[vc_column_text]We suggest using this method <strong>if you have little time or a lot of content to edit<\/strong>. Alternatively, if you want to uniformly change all instances of one word\/phrase with a new one, automatic replacement will do it for you.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Start by selecting your database from the <em>phpMyAdmin menu<\/em> on the left and clicking on the <em>SQL<\/em> tab.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Before we start querying the database, let\u2019s take a look at the form our query should take. The generic SQL query for an automatic replacement would look like this:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">update table_name set field_name = replace(field_name, 'text you are searching for', 'text to replace it');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]This query replaces all occurrences of the <em>text you are searching for<\/em> with <em>text to replace it<\/em> within the column called <em>field_name<\/em> located in a table called <em>table_name<\/em>.<br \/>\n[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>We will give you two examples you can edit to make your own query. <\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Make sure to replace the <em>text you are searching<\/em> and <em>text to replace it<\/em> expressions with the actual word\/phrase you need to change.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]In the first example, we\u2019re making changes to the <em>wp_postmeta<\/em> database table:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">UPDATE wp_postmeta SET meta_value = replace(meta_value,'text you are searching for','text to replace it');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]In the second example, we\u2019re making changes to the <em>wp_usermeta<\/em> table:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">UPDATE wp_usermeta SET meta_value = replace(meta_value, 'text you are searching for','text to replace it');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]These queries will help you <strong>run automatic search and replace on your database<\/strong>. Please note that we put together generic queries and you must adapt them if you want them to work for you. So, when you choose which table you\u2019ll be updating, <strong>make sure to add a column that actually exists within that table<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To illustrate, we\u2019re going to make the following query:[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">update wp_posts set post_content = replace(post_content,'work','play');<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]Press <em>Go<\/em> to run the query. It will automatically replace every occurrence of the word <strong><em>work<\/em><\/strong> with the word <em><strong>play<\/strong><\/em> inside the <em>post_content<\/em> column in the <em>wp_posts<\/em> table.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/11-Replace-every-occurrence-of-the-word.jpg\" class=\"attachment-full size-full\" alt=\"Replace every occurrence of the word\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/11-Replace-every-occurrence-of-the-word.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/11-Replace-every-occurrence-of-the-word-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/11-Replace-every-occurrence-of-the-word-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Once you run your query, <strong>wait until you get a message confirming that it\u2019s done<\/strong>. Depending on your database size it may take some time. The message you get will also list how many rows were affected by the change.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/12-List-how-many-rows-were-affected-by-the-change.jpg\" class=\"attachment-full size-full\" alt=\"List how many rows were affected by the change\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/12-List-how-many-rows-were-affected-by-the-change.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/12-List-how-many-rows-were-affected-by-the-change-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/12-List-how-many-rows-were-affected-by-the-change-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;82px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h3 class=\"qodef-h5\"><a id=\"adding-code-to-the-functions-php-file\"><\/a>How to Add Code to The functions.php File for Search and Replace<\/h3>\n<p>[\/vc_column_text][vc_column_text]Another method you can use to run search and replace on your website content involves creating custom functions. This means you need to be familiar with coding as you will be <a href=\"https:\/\/qodeinteractive.com\/magazine\/wordpress-functions-php-tricks\/\">making changes to the code inside the functions.php file<\/a><strong> of your theme<\/strong> (or child theme). Please note, this method targets only specific parts of your website. Before proceeding, <strong>make a copy of your functions.php file<\/strong> as backup in case of coding errors.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]To make functions-based changes to your website, you need to access the functions.php file of your theme or child theme. You can do this by connecting to your server using your FTP credentials and locating <strong>your root WordPress directory<\/strong> (public_html).[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/13-Adding-code-to-the-functions.php-file.jpg\" class=\"attachment-full size-full\" alt=\"Adding code to the functions.php file\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/13-Adding-code-to-the-functions.php-file.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/13-Adding-code-to-the-functions.php-file-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/13-Adding-code-to-the-functions.php-file-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Navigate to the <em>\/wp-content\/themes<\/em> directory and choose your currently active theme (in our case, that\u2019s Twenty Twenty). Find the <em>functions.php file<\/em>, right-click on it, and select <em>View\/Edit<\/em> from the dropdown menu.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/14-Functions-php-view-edit.jpg\" class=\"attachment-full size-full\" alt=\"Functions.php view edit\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/14-Functions-php-view-edit.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/14-Functions-php-view-edit-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/14-Functions-php-view-edit-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]Open the file using a text editor and scroll to the bottom. You will need to insert your custom function at the end of the file. We\u2019ve added a comment <em>\/\/ Your custom code goes here<\/em> to mark the spot. Please note that the <strong>forward slashes are a way to mark a line of code that will not be executed in PHP<\/strong>, so make sure to leave them out when adding your code.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;]<div class=\"qodef-single-image-holder   qodef-has-border \">\n    <div class=\"qodef-si-inner\" >\n                                    <img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"374\" src=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/15-Your-custom-code-goes-here.jpg\" class=\"attachment-full size-full\" alt=\"Your custom code goes here\" srcset=\"https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/15-Your-custom-code-goes-here.jpg 700w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/15-Your-custom-code-goes-here-300x160.jpg 300w, https:\/\/qodeinteractive.com\/magazine\/wp-content\/uploads\/2020\/05\/15-Your-custom-code-goes-here-620x331.jpg 620w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/>                        <\/div>\n<\/div>[vc_empty_space height=&#8221;38px&#8221;][vc_column_text]<strong>We are going to show you an example of what a custom function looks like.<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]The following code replaces all occurrences of the word job with the word task. Using the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/is_singular\/\" target=\"_blank\" rel=\"noopener noreferrer\">is_singular() function<\/a> and <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/the_content\/\" target=\"_blank\" rel=\"noopener noreferrer\">the_content hook<\/a> will<strong> restrict this functionality to the content of your pages and blog posts, keeping the rest of your site unaffected<\/strong>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">function find_and_replace_words( $text ) {\r\nif( is_singular( array( 'post', 'page' ) ) ){\r\n$replace_words = array(\r\n'job' =&gt; 'task',\r\n);\r\n$text = str_replace( array_keys( $replace_words ), $replace_words, $text );\r\n}\r\nreturn $text;\r\n}\r\nadd_filter( 'the_content', 'find_and_replace_words' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]To adapt this code, just replace <em>job<\/em> and <em>task<\/em> with the word\/phrase you want to change on your site.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]<strong>Extra tip<\/strong>[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]You can use the same function to <strong>change multiple words or phrases on your site<\/strong>. This is done by adding new entries in the <strong>$replace_words<\/strong> array, in the same manner as with the first entry (<strong>&#8216;job&#8217; &gt; &#8216;task&#8217;<\/strong>,). Moreover, you can <strong>change a range of things at the same time<\/strong>. For example, you can add links and replace words with the same custom function simultaneously. To illustrate, the following code will add an Instagram link to every occurence of the word <em>Instagram<\/em> on your posts and pages. At the same time, it will replace <em>job<\/em> with <em>task<\/em>.[\/vc_column_text][vc_empty_space height=&#8221;50px&#8221;][vc_column_text]<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">function find_and_replace_words( $text ) {\r\nif( is_singular( array( 'post', 'page' ) ) ){\r\n$replace_words = array(\r\n'Instagram' =&gt; '&lt;a href=\"https:\/\/www.instagram.com\/\"&gt;Instagram&lt;\/a&gt;',\r\n'job' =&gt; 'task',\r\n);\r\n$text = str_replace( array_keys( $replace_words ), $replace_words, $text );\r\n}\r\nreturn $text;\r\n}\r\nadd_filter( 'the_content', 'find_and_replace_words' );<\/pre>\n<p>[\/vc_column_text][vc_empty_space height=&#8221;18px&#8221;][vc_column_text]When you\u2019re done,<strong> save the changes and upload the edited functions.php file<\/strong> back to the server to overwrite the old one. Doing this will apply the changes to your site content.[\/vc_column_text][vc_empty_space height=&#8221;28px&#8221;][vc_column_text]Now, the code above (and any variation of it you make) won\u2019t alter the content of your database or the backend content of your page. It will only<strong> change the frontend display visible to users<\/strong>. Because of that,<strong> using this method to perform search and replace on your site can be restrictive<\/strong>. However, you can combine it with any of the other methods described in this article.[\/vc_column_text][vc_empty_space height=&#8221;68px&#8221;][\/vc_column][\/vc_row][vc_row][vc_column][vc_column_text]<\/p>\n<h2 class=\"qodef-h4\">Final Thoughts<\/h2>\n<p>[\/vc_column_text][vc_column_text]As we\u2019ve seen, there are several ways to run find and replace on your site content. We hope you found one of them helpful and that you learned something new about WordPress tables, queries, and custom PHP functions along the way. Before you start to make changes on your own, keep in mind that performing search and replace can have serious effects if done improperly. Anything is possible\u2014from crashing your site due to database errors to slowing down its speed with too much custom code. So you should <a href=\"https:\/\/qodeinteractive.com\/magazine\/how-to-manually-backup-wordpress-website\/\">make a backup<\/a> and have a <a href=\"https:\/\/qodeinteractive.com\/magazine\/manually-restore-wordpress-website-backup\/\">way to restore your site<\/a> prepared, just in case.[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Do you need to run a search and replace in WordPress? Is there one tiny word or phrase you need to change and want to know how? We have the answers.<\/p>\n","protected":false},"author":11229,"featured_media":7940,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[14,4,13],"class_list":["post-7849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-core","tag-tips","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/7849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/users\/11229"}],"replies":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/comments?post=7849"}],"version-history":[{"count":0,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/posts\/7849\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media\/7940"}],"wp:attachment":[{"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/media?parent=7849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/categories?post=7849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qodeinteractive.com\/magazine\/wp-json\/wp\/v2\/tags?post=7849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}