Developers delight! You can now manage your WordPress site right from the command line using WP-CLI. Managing your site directly from the command line is definitely faster than managing it from a web browser. For more information about WP-CLI, you can refer to the WP-CLI Handbook. ๐Ÿ‘ฉโ€๐Ÿ’ป

Also, check out An Introduction to WP-CLI by Pascal Birchler.

Default WP-CLI Commands

Since there are a lot of functions that are supported by WP-CLI, there are separate commands to execute each action. But most of them are straight forward. For example, the โ€˜wp adminโ€™ command opens your admin area in the web browser whereas the โ€˜wp configโ€™ command generates and reads the wp-config.php file.

Some commands have subcommands which allow you to fine-tune your query.

For example, the โ€˜wp mediaโ€™ command allows you to list, create, assign, and delete an active themeโ€™s navigation menu. But to perform each of this action, you need to use different subcommands โ€“

  • wp menu to create a new menu
  • wp menu delete to delete one or more menus
  • wp menu list to get a list of menus

Here is a list of all the default WP-CLI commands โ€“ WP-CLI Commands.

Other useful commands

  • wp profile command โ€“ Quickly identify whatโ€™s slowing your WordPress site
  • wp doctor command โ€“ Diagnose problems within WordPress by running a series of checks for symptoms

Create custom commands in WP-CLI

Apart from the default commands, you can also create your own custom WP-CLI commands. Thatโ€™s the level of flexibility it offers. Also, thereโ€™s no limit to what you can do with WP-CLI when you are managing your website from the command line.

For more information on how to create custom WP-CLI commands, have a look at the Commands Cookbook.

How to export or import DB with WP-CLI

Using WP-CLIโ€™s โ€˜wp dbโ€™ command, you can even export or import your database right from the terminal. Have a look at the below subcommands to read more about them.

  • wp db export โ€“ Exports the database to a file or to STDOUT.
  • wp db import โ€“ Imports a database from a file or from STDIN.

Useful links