Manage WordPress Using WP-CLI

All of our Shared and Reseller packages have a very powerful command line interface for managing WordPress call WP-CLI installed by default. Though this document was meant to offer a lot of basics and go through some very important features of WP-CLI it is recommended to explore the official documentation for additional information: https://developer.wordpress.org/cli/commands/

Accessing WP-CLI

1. Login to cPanel and click on the button that says Terminal. In most cases you enter your home directory upon accessing Terminal. Type cd public_html or cd foldername to navigate to your WordPress site. For instance, if you have a domain called mycooldomain.com in /home/eric/mycooldomain.com  you would type cd mycooldomain.com. If you had a domain in your public_html folder you would just type cd public_html.

2.  Type wp or wp help to display the default help message. This will display a list of commands. You can always enter wp help <commandname> for more information about a command. For instance: wp help help will display information about the help command. NOTE: When accessing help in wp-cli, you can type q to quit and space bar or the up or down arrow keys on your keyboard to navigate through the help files. 

Useful WP-CLI Commands

Below is a list of useful commands with an explanation for each command. This list is not exhaustive, but this will provide some very useful commands for managing your WordPress site from the command line. 

  • wp help - Lists all commands.
  • wp help <command> <optional subcommand> - Get more help on a specific command and display possible subcommands For instance, wp help helpwp help plugin , or wp help core download
  • wp core download - Download and extract all default WordPress core files to your current directory. You would use this if somehow WordPress files became corrupted or were missing. In most cases plugins, themes, etc should not update these files, so it is usually safe to run this command to restore your core files as long as you have a backup just in case. NOTE: If WordPress is already installed, you can also run wp core download --force
  • wp core version - Show WordPress core version
  • wp core update - Update to most recent WordPress core version.
  • wp plugin list - List all installed plugins
  • wp plugin search <keyword> - Search for plugins that contain keyword. For instance wp plugin search yoast will provide all plugins that contain "Yoast" in the name or description of the plugin. The slug name for each plugin is what you will enter to install or remove the pluginblobid0.png
  • wp plugin install <slug name>. Installs a WordPress plugin with the slug name provided in wp plugin search. For instance, when you searched in the above example you found out wordpress-seo is the slug name for Yoast SEO. To install this plugin you would just enter wp plugin install wordpress-seo.
  • wp plugin install <slug name> -activate - Installs a WordPress plugin with the slug name provided and activates the plugin. 
  • wp plugin activate <slug name> - Activates a WordPress plugin. For instance in the example above you could type wp plugin activate wordpress-seo.
    • Note: You can utilize this command to activate multiple domains as well e.g wp plugin activate wordpress-seo duplicate-post yoast-test-helper
  • wp plugin update <slug name> - Updates a WordPress plugin. In the above example you would type wp plugin update wordpress-seo
  • wp plugin deactivate -all - Deactivates all plugins. This can be helpful if one or more plugins is causing an issue with your site. 
  • wp plugin activate -all - Activates all currently installed plugins.
  • wp theme list - Lists all themes installed
  • wp theme install twentytwenty -activate - Installs and activates the twentytwenty theme.
  • wp theme delete twentytwenty - Deletes twentytwenty theme.
  • wp theme disable twentytwenty - Disable twentytwenty theme.
  • wp search-replace 'oldstring' 'newstring' - Search the database for oldstring and replace with newstring. For instance wp search-replace 'oldsite.com' 'newsite.com' would replace all instances of oldsite.com with newsite.com within the database.
  • wp user list -all  - List all WordPress users
  • wp user list -role=administrator - List all WordPress administrator users
  • wp user reset-password <username> - Reset password for the username you choose.
  • wp config get - View wp-config configuration
  • wp config set WP_DEBUG false - disable WP_DEBUG mode
  • wp config set WP_DEBUG true - enable WP_DEBUG mode

These are just a couple useful WP-CLI commands. To learn more you should check out the official documentation at https://developer.wordpress.org/cli/commands/

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.