WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installations and much more, without using a web browser.
WP-CLI stands for WordPress-Command-Line-Interface, it is the DOS-box or Terminal equivalent for WordPress. With it you can update plugins, themes, execute commands backup the WP database and much, much more.
The WordPress dashboard has always been the centre of WordPress management, sure there’s loads of management plugins, services and utilities but there was little support for back-end developers to automate or perform tasks (especially if managing several or even hundreds of WordPress sites) easily.
Then came wp-cli, the command line interface for WordPress. First released as version 0.3.0 on November 6th 2011. It can be used to automate many tasks, download install a fresh WordPress site and lots more.
Down to the nitty gritty, what can it do for you?
A full list of commands can be found here. Below is a common list of what we run here at Fortifli.
The basic command structure is
/path/to/wp --path=/path/to/your/wordpress
1. Cron jobs
WordPress has an internal cron system which by default is checked every time someone visits your site. It is used by themes and plugins to do anything from checking cache, posting scheduled posts at the post-date to checking for updated versions of plugins, themes and the WordPress version itself. On a busy site this can cause undue resource utilisation as each visit will tell WordPress “Hey buddy is there anything that needs running?”.
By disabling this functionality you can restore some performance on WordPress in your wp-config file:
define('DISABLE_WP_CRON', 'true');
Then have your hosting execute wp-cli
wp cron event run --due-now
For eg:
/usr/local/bin/wp cron event run –due-now –path-/home/public_html
Set your cron job to run this every 5 minutes and everything needed to be run will be run!
2. List plugins (or themes)
wp plugin list
This will show something like:
+---------------------------+----------+-----------+---------+ | name | status | update | version | +---------------------------+----------+-----------+---------+ | akismet | active | none | 4.1.4 | | classic-editor | active | none | 1.5 | | contact-form-7 | active | none | 5.1.7 | | no-category-base-wpml | active | none | 1.3 | | wordfence | active | none | 7.4.6 | | advanced-cache.php | dropin | none | | +---------------------------+----------+-----------+---------+
Listed here are the details, the name, whether the plugin is active or not, if there’s an update available and the plugin version.
wp theme list
+----------------+----------+-----------+---------+ | name | status | update | version | +----------------+----------+-----------+---------+ | twentynineteen | active | available | 1.4 | | twentytwenty | inactive | available | 1.1 | +----------------+----------+-----------+---------+
Above you can see that the twentynineteen theme is active and there is an update available for both themes.
3. Update WordPress Version
wp core update
wp core update-db
Note: If you are updating WordPress using wp-cli, always ensure that the wp core update-db is run, as even if the WP database does not need an update (it often doesn’t) but not running this could cause unexpected results!
4. Update all plugins and themes
wp theme update --all
wp plugin update -–all
5. Backing up the database
With WordPress the database is the very core of itself, so whilst taking daily backups may suffice for the WP files (including core files, plugins,themes and of course images) the database is very important so you may want to back up just the database at scheduled times throughout the day.
wp db export
Success: Exported to ‘somefile.sql’.
Note that this file is always named uniquely unless an output file name is specified the structure is today’s date>-.sql
Security note: NEVER EVER EVER EVER (Did I say EVER enough?) leave these .sql files in a publicly accessible area on your host. SQL files are a commonly scanned for by hackers attempting to download your content/passwords/usernames etc.
6. Regenerate thumbnails
No longer do you need a plugin for this just:
wp media regenerate
This will regenerate all of your image thumbnails in the wp-content/uploads directory.
7. Search-Replace
Ever use Better Search Replace? To update urls? Us too! But with wp-cli this is a breeze and also much faster.
For example, lets say you’ve just activated SSL, but a lot of your links within WordPress are still http://yoursite.tld?
No worries!
wp search-replace http://yoursite.tld https://yoursite.tld
This will update all links (including images) in your entire database. With great power, comes great responsibility – be very careful with this! You can use the–dry-run switch to see what will be changed beforehand.
We also use this when building staging sites for clients, simply setup a new install with a fresh copy from the live site and then
wp search-replace https://yoursite.tld https://stage.yoursite.tld
Done!
The above 7 commands can save you loads of time, but barely scratches the surface of what wp-cli can do, checkout the full list of commands, switches and examples at Developer.WordPress.org you will be amazed at what you can achieve.
Great! I year you say, but how do I know if my host has this installed? Naturally if you are a client of Fortifli, this is already available.
If you have a dedicated or VPS server, then you can follow these instructions, or if you are on shared hosting, many such as Siteground, Bluehost and more already have it right there waiting for you. Not sure? Then just ask your hosting provider’s support.
Already familiar with wp-cli? Comment below and let us know how you put it into use.

