WP-CLI
WP-CLI is a command-line interface for managing WordPress sites. It allows you to perform various administrative tasks from the command line. Follow these steps to use WP-CLI:
Install WP-CLI
chmod +x wp-cli.phar
.mv wp-cli.phar /usr/local/bin/wp
.Basic Commands
wp --version
to check the installed version of WP-CLI.wp core update
to update WordPress core to the latest version.wp plugin install plugin-slug
to install a plugin.wp plugin activate plugin-slug
to activate a plugin.wp plugin update plugin-slug
to update a plugin.wp user create username [email protected] --role=author
to create a new user.Manage Themes
wp theme install theme-slug
to install a theme.wp theme activate theme-slug
to activate a theme.wp theme update theme-slug
to update a theme.Manage Posts
wp post create --post_title="Post Title" --post_content="Post content." --post_status=publish
to create a new post.wp post list
to list all posts.wp post delete post-id
to delete a post.Best Practices
- Backup: Always backup your site before running WP-CLI commands that modify data.
- Test Commands: Test WP-CLI commands on a staging site before running them on your live site.
- Use Help: Use the
wp help
command to get help with WP-CLI commands and options.