Skip to content
WebHostsOnline Web-Solutions
  • Home
  • Domains
    • Domains
    • Transfer Your Domain
    • Order SSL Certificates
  • Cloud Hosting
    • AWS Hosting
    • Cloud i Hosting from WebHostsOnline
    • Google Cloud Servers
    • Magento Hosting
    • WooCommerce Hosting
    • Timeline Backups
  • Hosting
    • Shared Hosting
    • Website Builder
    • Website Design & Hosting
  • Email Hosting
  • WordPress
    • Free Hosting
    • WooCommerce Hosting
    • WordPress Hosting
  • VPS Hosting
  • Tools
    • SSL Certificates
    • Timeline Backup-Pro
    • Website Turbo
  • My Account
Contact Us
alt
WebHostsOnline Web-Solutions
  • hello@webhostsonline.co.uk
back to top

How do I run a search and replace in the WordPress CLI?

  • WebHostsOnline Web-Solutions
  • /knowledge-base
  • Web Hosting
  • How do I run a search and replace in the WordPress CLI?

My Account

3
  • How do I register a new domain with WebHostsOnline?
  • Which nameservers should I use with WebHostsOnline hosting?
  • Where can I update my account / profile details?

Cloud Servers

10
  • How do I add another server/include to an SPF record?
  • Managed Cloud Server: Manage Your Cloud Server
  • Managed Cloud Server: Registering Domain Names
  • How can I clone a site with Timeline Backups?
  • How do I restore a site using Timeline Backups?
  • How do I set up Automatic Timeline Backups?
  • Does your hosting support Django?
  • Does your Windows hosting support .NET Core?
  • How do I activate my free SSL?

Domains

10
  • How can I create a subdomain?
  • Managed Cloud Server: Registering Domain Names
  • Domain transfer statuses explained?
  • What are WebHostsOnline nameservers?
  • How to transfer your domain from 123-reg WebHostsOnline
  • How to transfer your domain from Ionos to WebHostsOnline
  • How to transfer your domain from GoDaddy to WebHostsOnline
  • How to transfer your domain from Easyspace to WebHostsOnline
  • My domain is locked with my current provider, what can I do?
  • How do I transfer my domain to you?

Email Hosting

13
  • How to create an autoresponder?
  • How do I add Office 365 DNS records?
  • Why are the IMAP folders missing from my iPhone or iPad?
  • What are the recommended Thunderbird Mail client settings?
  • How do I add another server/include to an SPF record?
  • WordPress: use SMTP with and without plugins
  • What are the Free Tools with WordPress Hosting?
  • How do I use the free WebHostsOnline Website Malware Scanner? 
  • What are my email sending limits?
  • How do I set up email on my iPhone?
  • How do I set up my WebHostsOnline mailbox in Outlook?
  • How do I create a mailbox?
  • How to use the email migration tool

FTP

2
  • How to connect Web Hosting via FTP?
  • I can’t connect via FTP, what can I do?

Web Hosting

18
  • How can I clone a site with Timeline Backups?
  • How do I restore a site using Timeline Backups?
  • How do I set up Automatic Timeline Backups?
  • Does your hosting support Django?
  • WordPress caching: what you need to know
  • Do I need caching plugins in addition to the WebHostsOnline CDN?
  • Why am I getting a cache status ‘MISS’?
  • How do I use WebHostsOnline’s CDN?
  • How do I create a Website Acceleration Suite template?
  • Improve your WordPress website’s TTFB
  • What is the Website Acceleration Suite?
  • Why could my WordPress migration fail?
  • Do you support WordPress multisite?
  • How do I activate my free SSL?
  • How do I run a search and replace in the WordPress CLI?
  • How do I create a MySQL database in MyWebHostsOnline
  • How do I change PHP version?
  • How to modify your hosts file for Windows, macOS and Linux.

WordPress

21
  • I installed WordPress on the temporary URL, how can I change it to my domain name?
  • WordPress Multisite Setup Guide
  • How can I clone a site with Timeline Backups?
  • How do I restore a site using Timeline Backups?
  • How do I set up Automatic Timeline Backups?
  • Why do I get an Internal Server Error 500 and how to fix it?
  • WordPress: use SMTP with and without plugins
  • WordPress caching: what you need to know
  • Do I need caching plugins in addition to the WebHostsOnline CDN?
  • Why am I getting a cache status ‘MISS’?
  • How do I use WebHostsOnline’s CDN?
  • How do I create a Website Acceleration Suite template?
  • Improve your WordPress website’s TTFB
  • What is the Website Acceleration Suite?
  • Why could my WordPress migration fail?
  • Do you support WordPress multisite?
  • How do I activate my free SSL?
  • How do I run a search and replace in the WordPress CLI?
  • Is it safe to update the PHP version on my website?
  • How do I migrate a website manually?
  • WooCommerce
    • WordPress Multisite Setup Guide

Migrations

3
  • Why could my WordPress migration fail?
  • How do I migrate a website manually?
  • How to modify your hosts file for Windows, macOS and Linux.

SSL Certificates

2
  • How do I activate my free SSL?
  • Can I use the free SSL if my site doesn’t use the WebHostsOnline nameservers?

Security

3
  • What are the Free Tools with WordPress Hosting?
  • How do I use the free WebHostsOnline Website Malware Scanner? 
  • Protecting your password from brute-force attacks

DataBase

13
  • How to connect Web Hosting via FTP?
  • MS-SQL
    • How do I import a .sql file via the command-line?
    • How do I manage my Microsoft SQL database?
    • What is MS-SQL?
  • MySQL
    • How do I export a .sql file via the command-line
    • How do I download or back up my MySQL Database?
    • How do I import a .sql file via the command-line?
    • Can I view my FTP, email address, or database passwords?
    • How do I create a MySQL database?
    • What’s the maximum MySQL database size allowed?
    • Can I set my database hostname as ‘localhost’?
    • How do I import a .sql file via phpMyAdmin?
    • What is MariaDB?

VPS

14
  • How do I connect to my Windows virtual machine via Remote Desktop?
  • How set up Mastodon on a Self-Managed VPS
  • How do I connect to an Unmanaged VPS using SSH?
  • How do I install and enable Apache and PHP modules on my cPanel VPS?
  • Does your hosting support Django?
  • How do I raise an additional IP address on my CentOS virtual machine?
  • How do I add an additional IP address to my virtual machine?
  • What version of Windows do you run on the Windows servers?
  • Does your Windows hosting support .NET Core?
  • How do I connect to my Windows virtual machine via Remote Desktop?
  • Windows
    • How do I connect to my Windows virtual machine via Remote Desktop?
    • Managing the Windows Application Pool
    • What version of Windows do you run on the Windows servers?
    • Does your Windows hosting support .NET Core?

Backups

3
  • How can I clone a site with Timeline Backups?
  • How do I set up Automatic Timeline Backups?
  • How do I restore a site using Timeline Backups?

SSH

8
  • Can I use sudo on shared hosting?
  • What is the PHP memory_limit?
  • How do I connect via SSH using 2FA?
  • How do I connect via SSH?
  • How do I import a .sql file via the command-line?
  • How do I connect via SSH on an Apple Mac?
  • How do I connect via SSH on an Apple Mac?
  • How do I run Composer via SSH?
View Categories
  • Home
  • /knowledge-base
  • Web Hosting
  • How do I run a search and replace in the WordPress CLI?

How do I run a search and replace in the WordPress CLI?

4 min read

AI Doc Summarizer Doc Summary
AI Doc Summarizer Thinking Thinking

The WordPress Command Line Interface (CLI) search and replace function is a useful tool when you need to make global changes to your WordPress site’s content. 

Some common use cases for this function include:

  1. Changing the site URL: If you’re moving your WordPress site to a new domain or subdomain, you can use the search and replace function to replace all instances of the old URL with the new one.
  2. Updating internal links: If you’ve made changes to the structure of your site and need to update internal links, you can use the search and replace function to find and replace those links quickly and easily.
  3. Replacing deprecated code: If you’re using outdated code on your site, you can use the search and replace function to replace it with updated, functional code.
  4. Updating plugin settings: If you need to update settings for a specific plugin across your site, you can use the search and replace function to make the change to all instances of the plugin’s settings in the database.
  5. Cleaning up data: If you need to remove specific text or data from your site, you can use the search and replace function to find and replace that data with an empty string.

It’s important to understand that the search and replace function operates directly on the WordPress database, so it’s essential to back up your database before running the command to avoid any potential data loss. We’d recommend taking a snapshot of your site files and database prior to running the search and replace. Additionally, it’s recommended to test the function on a staging site before making any changes to your live site.

To use the search and replace function, you’ll need to access your website via the command line through SSH and navigate to the directory where WordPress is installed. If you’re unsure about how to connect via SSH then please see this guide: How to connect through SSH.

From there, you can run the following command: 

wp search-replace old-string new-string [--network] [--dry-run]

Where:

‘old-string’ is the string you want to search for and replace.

‘new-string’ is the string you want to replace old-string with.

–network is an optional argument that, when used, will perform the search and replace operation on all sites in a WordPress network.

–dry-run is an optional argument that, when used, will perform a dry run of the search and replace operation, meaning it will show you what would be changed, but will not make any actual changes to the database.

For example, if you wanted to replace your temp URL with the live domain name, you’d enter the following: 

wp search-replace domain-com.stackstaging.com domain.com

The above would immediately make all the appropriate replacements. If you’d rather perform a ‘dry run’ first then you’d need to enter the ‘–dry-run’ flag at the end of the command:

wp search-replace domain-com.stackstaging.com domain.com --dry-run

To perform the action across all sites on the WordPress Network (Multisite) then run the following: 

wp search-replace domain-com.stackstaging.com domain.com --network

What are the risks involved with using Search and Replace in the WP CLI?

  • Data loss: if the search and replace function is not used correctly, it can result in data loss. For example, if you use the function to search for a string that’s found within another string in the database, it could result in unintended changes. It’s important to back up your database before using the function to ensure that you can restore your site if any issues arise.
  • Incorrect replacements: if you make a mistake in the search or replace string, it can result in incorrect replacements in the database. This can lead to broken links, incorrect display of content, or other issues on your site.
  • Incompatible changes: if you’re using a plugin or theme that adds custom data to the database, the search and replace function may not be compatible with that data. It may result in unexpected changes or errors.
  • Search and replace errors: if there are any errors in the search and replace function, it could result in incomplete replacements or other issues with the database.

In conclusion, it’s important to use the WordPress CLI search and replace function with caution and to thoroughly test the function before using it on a live site.

It’s also recommended to have a good understanding of how the function works and the potential issues that can arise. This way, you can avoid any problems and ensure a smooth and successful search and replace operation.

Updated on September 24, 2025

What are your Feelings

  • Happy
  • Normal
  • Sad

Share This Article :

  • Facebook
  • X
  • LinkedIn
  • Pinterest
How do I activate my free SSL?How do I create a MySQL database in MyWebHostsOnline

Powered by BetterDocs

Leave a Comment Cancel reply

WebHostsOnline Web-Solutions

Contact

  • Church Yard,
    Ashford Kent.
    TN23 1QG
  • hello@webhostsonline.co.uk

Links

  • Cloud Hosting
  • Joomla Hosting
  • Laravel Hosting
  • .Net Core Hosting
  • NodeJS Hosting
  • PHP Hosting
  • VPS Hosting
  • My WebHostsOnline Demo
  • WebMail

Support

  • Contact Us
  • Knowledge Base
  • System Status

Company

  • About
  • Blog
  • Cookie Policy
  • Disclaimer
  • Imprint
  • Privacy Statement
  • Terms and Conditions
  • Website Design Service Terms and Conditions of Service

All rights reserved © WebHostsOnline Web-Solutions. | Part of the GMCi Group
Registration No. 17215955, Registered in England and Wales.

Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behaviour or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
View preferences
{title} {title} {title}