Portal Home Knowledgebase 3. WordPress How to Use the WP-CLI to Manage Your WordPress Site

How to Use the WP-CLI to Manage Your WordPress Site Print

  • 0

With WP-CLI, you can perform various actions on your WordPress site directly from the command line. Below is a compilation of essential commands you can utilize for different tasks.

1. Install and Update WordPress

  • Download WordPress:

     
    wp core download
  • Download a Specific Locale Version:

     
    wp core download --locale=en-US
  • Install WordPress:

     
    wp core install --url=testing.com --title=Example --admin_user=supervisor --admin_password=strongpassword --admin_email=info@testing.com

    (Replace the default values with your credentials.)

  • Test the Installation:

     
     
    wp core version
  • Update to the Latest Version:

    wp core update

2. Manage Themes and Plugins

Managing Themes:

  • List Installed Themes:

     
    wp theme list
  • List Inactive Themes in CSV Format:

     
    wp theme list --status=inactive --format=csv
  • Activate a Theme:

     
    wp theme activate twenty-twenty
  • Search for Themes:

     
    wp theme search bootstrap
  • Install and Activate a Theme:

     
    wp theme install the-bootstrap-blog --activate
  • Update All Themes:

     
    wp theme update --all

Managing Plugins:

  • List Installed Plugins:

     
    wp plugin list
  • Install and Activate a Plugin:

     
    wp plugin install litespeed-cache --activate
  • Update All Plugins:

     
    wp plugin update --all
  • Deactivate and Uninstall a Plugin:

     
    wp plugin deactivate litespeed-cache --uninstall
  • Activate an Inactive Plugin:

     
    wp plugin activate litespeed-cache
  • Delete a Plugin:

     
    wp plugin delete litespeed-cache

3. Create a Child Theme

Creating a child theme ensures your customizations are preserved during updates.

  • Generate a Child Theme:
     
    wp scaffold child-theme twenty-twenty-child --parent_theme=twentytwenty
    (This creates a child theme based on the Twenty Twenty theme.)

4. Moderate Comments

You can efficiently manage comments using WP-CLI.

  • Add a New Comment:

     
    wp comment create --comment_post_ID=10 --comment_content="This is my comment" --comment_author="author-name"
  • List Approved Comments:

     
    wp comment list --number=5 --status=approve --fields=ID,comment_author
  • Delete a Comment:

     
    wp comment delete 46
  • Permanently Delete Multiple Comments:

     
    wp comment delete 3 25 46 54 --force

5. Update WP-CLI

Keeping WP-CLI updated is crucial for optimal performance.

  • Update WP-CLI:
     
    wp cli update

If your version is not updated, you will be prompted to accept the installation.

By utilizing these commands, you can significantly enhance your productivity and perform tasks that are not readily available in the WordPress admin panel. WP-CLI is a powerful tool for both beginners and experienced developers alike.


Was this answer helpful?

« Back