This tutorial covers the following topics:
WP-CLI is the command-line interface for WordPress, allowing you to manage all aspects of the application from the command prompt, without having to use a web browser. It's a very powerful tool that could help you complete complex tasks that would otherwise require additional plugins or would take much more time to accomplish.
This tutorial focuses on using WP-CLI to complete typical WordPress administration tasks, such as updating themes and plugins, managing the dashboard users, and changing the site's URL settings. Note that WP-CLI is available on all servers, but it requires SSH access. Thus, you will first need to make sure that you have enabled SSH access for your account. You can do that through the "SSH Access" section of the hosting Control Panel. More information on SSH is available in the following articles from our online documentation:
Once logged into your account over SSH, you will need to navigate to the location of your WordPress site. If you are looking to manage the site for your main domain name and you have not changed the default web root folder, you will need to run the following command:
If your WordPress site is located in another directory, you will need to navigate to that directory instead. Now that you are in the WordPress directory, you can start executing WP-CLI commands.
Obtaining a list of the available WP-CLI commands
You can obtain a list of all the available WP-CLI commands by running the following
Updating the WordPress core
You should first check the current version of your WordPress installation by running the following command:
wp core version
You can start the update with the following command:
wp core update
If there are no updates available, you will receive the following message:
Success: WordPress is up to date.
Updating WordPress plugins
Again, you should first check the status of the installed plugins, and that's done by running:
wp plugin list+---------------------+--------+-----------+---------+
We have a total of nine plugins installed in our sample WordPress project. You can see under the Status column that all of them are currently active and there are updates available for four of them. Here is how we can update one of the plugins:
wp plugin update fusion-builderEnabling Maintenance mode...
Installing and activating/deactivating plugins
Here are the commands for installing, activating, and deactivating plugins:
wp plugin install plugin_namewp plugin activate plugin_namewp plugin deactivate plugin_name
You should replace the plugin_name string with the actual name of the plugin. Deactivating plugins via the command line can be quite helpful if you have a plugin that has caused an issue with your website and yet you cannot log in at the dashboard with a browser, in order to deactivate it. In such cases, you would still be able to log into your account via SSH and deactivate the problematic plugin from the command line using WP-CLI.
Managing WordPress themes
Here are the most common commands for managing the WordPress themes:
wp theme listwp theme activate theme_namewp theme delete theme_namewp theme install theme_namewp theme update theme_name
The first command shows you a list of the themes currently installed, and here is the output when executed in our sample installation:
wp theme list+-----------------+----------+-----------+---------+
This table shows there are three themes installed with updates available for all of them. Here is how a theme can be updated via the command line:
wp theme update twentyseventeen
Managing WordPress users
This command is helpful if you have forgotten the password for a given user and do not have access to the email account associated with it.
wp user create USERNAME EMAIL --role=administrator
You should replace the USERNAME string with the desired username and the EMAIL with his/her actual email address. The "role" field sets the role of the user to create; the possible values are: ‘administrator’, ‘editor’, ‘author’, ‘contributor’, ‘subscriber’. Here is an example:
Changing the WordPress URL
CMS applications like WordPress are configured to work and accept requests over a specific URL. This URL is set during the installation process. However, it's often required to change it for a number of different reasons. For example, you might have to move your WordPress installation from one subdomain or subfolder to another, or may wish to change your domain name. Another fairly common situation is whenever you wish to force HTTPS connections to your website after installing an SSL certificate. This is a fairly complex task as it requires an update of all the database entries containing the old URL to the new one. The process is much easier with the use of WP-CLI, as you just need to run the following command:
wp search-replace 'http://your-old-URL.com' 'http://your-new-URL.com' --skip-columns=guid
Your site should now be configured to work over the new URL. Don't hesitate to open a support ticket in case you detect any issues.
Note: There may be hard-coded links to resources in your files that contain the old URL. If you notice missing images, CSS files, or any other discrepancies, you may want to check the browser's error console for specific errors. You can open the error console by clicking F12. It will help you locate files that may contain links to missing resources. You may also open a support ticket for help.