
WP-CLI, short for WordPress Command Line Interface, is a powerful and versatile tool designed to facilitate the management of WordPress websites through the command line. It provides a command-line interface for developers, administrators, and power users to interact with various aspects of their WordPress installations directly from the terminal.
With WP-CLI, users can perform a wide range of tasks very efficiently. This command-line interface streamlines and automates many routine tasks, offering an efficient alternative to traditional web-based administrative interfaces.
Enough with the introduction, here are some commands you can use with WP-CLI to make your WordPress website management easier.
If you need to search and replace something on your WordPress site, this is probably one of the easiest ways.
wp search-replaceFor example, it can be used to search and replace a URL after moving a website.
wp search-replace <old-url> <new-url>More details on how to use this command.
With WP CLI, you can import…
wp db import… or export a databaseWhere all WordPress content, settings, and user data are sto... More.
wp db exportThis is much faster than going through PHPMyAdmin or other databaseWhere all WordPress content, settings, and user data are sto... More tools for this, very useful to do a quick backupA copy of your WordPress site's files and database, saved to... More before making some changes.
More details on how to use the db import and db export commands. There are also many other commands available for databaseWhere all WordPress content, settings, and user data are sto... More interaction.
Sometimes, pluginSoftware that adds specific features or functionality to a W... More updates don’t go as planned and you end up with a broken site. The following command allows you to deactivate the faulty pluginSoftware that adds specific features or functionality to a W... More to get your website back on track and be able to work on the issue.
wp --skip-themes --skip-plugins plugin deactivate faulty-plugin-slugMore details on how to use this command.
To ensure that your WP CLI install is working properly, you can run this command and check the details.
wp --infoFor larger sites, postDynamic, time-based content (e.g., blog entries) displayed i... More revisions can take up quite a bit of space. From time to time, it’s a good idea to clean up revisions, as they are often unnecessary. To use this command, you will need to install the wp-revisions-cli package.
wp revisions clean --post_id=ID --before-date=DATEAnother maintenance routine you should consider for your WordPress site is to repair and optimize your databaseWhere all WordPress content, settings, and user data are sto... More on a regular basis.
To repair your databaseWhere all WordPress content, settings, and user data are sto... More with WP-CLI:
wp db repairTo optimize your databaseWhere all WordPress content, settings, and user data are sto... More with WP-CLI:
wp db optimizeWhen you are updating a website, especially a larger one, it’s a good idea to put it on maintenance mode before starting upgrades, in order to not have some processes disturbed by the update.
To activate maintenance mode with WP-CLI, you can just use this:
wp maintenance-mode activateTo deactivate it, just use this command:
wp maintenance-mode deactivate
If you lose your password as an administrator in WordPress and you have no access to the email the account was created with (for example: when you take over a new website), you can go to PHPMyAdmin to modify the password directly in the databaseWhere all WordPress content, settings, and user data are sto... More, or you can just use WP-CLI and do it much quicker.
wp user update admin@website.com --user_pass=new-passwordAs a developper, you know that to create a child theme in WordPress is the best way to customize an existing themeTheme A collection of files that determine a site's design, ... More and survive updates. To do it with WP-CLI, use a function like this:
wp scaffold child-theme slug-of-child-theme --parent_theme=slug-of-parent-theme --theme_name=theme-titleWhen you install a new instance of WordPress, it can be useful to have filler content to properly test it. For that, you can just use the generate command this way and create as many posts as you want (the following example generates fifteen posts).
wp post generate --count=15See all the options for this command on this page.