We recently made a list of the most useful WP-CLI commands with examples and how to fix the most common WPCLI errors but there are a lot of maintenance tasks that can be done with WP-CLI that We haven’t included in this list.
One of those tasks is reinstalling WordPress Core using WP-CLI.
Step 1. Get WordPress version
First, navigate to the directory where WordPress is installed and check the active version with
wp core version
Step 2. Delete wp-admin and wp-includes directories (optional)
One of the most common reasons We reinstall WordPress core is because the website was hacked and We want to get rid of any malicious files inside wp-admin and wp-includes directories.
rm -rf wp-admin wp-includes
- rm stands for remove and we are using
- -r for recursive to delete all the subdirectories and files
- -f for force without prompting.
Step 3. Reinstall WP core
To download the core files, while skipping the content folder (wp-content).
wp core download --force --skip-content --version=5.4.4
You can also specify the locale if needed with –locale:
wp core download --force --skip-content --locale=en_US --version=5.4.4