8 WP-CLI Commands to Clean Up and Optimize your Site
Want to clean up your WordPress site without having to add multiple plugins? By using WP-CLI, you can run many useful commands to helpfully clean up your database and elements related to your site. In this post, many of the most common tasks are covered:
- Purging Cache
- Regenerate Thumbnail Images
- Deleting Spam Comments
- Removing Temp Data from Database
- Optimizing a Database
- Deleting Posts in Trash
- Deleting Posts in Draft Status
- Delete Posts With Revisions
Purging Cache
In this example, object caching is enabled on the site on our Managed WordPress or Managed WooCommerce, if you need to clear the object cache, use:
Regenerate Thumbnail Images
If you changed the theme you were using on your site (which might be setting different image sizes), or if you changed the product image sizes in WooCommerce but now need to regenerate all thumbnail images, you can run this command:
Deleting Spam Comments
If you have comments enabled on your site and you want to delete all spam comments. Only run this command if you know that you do have comments marked as spam on your site, then you can run this command:
wp comment delete $(wp comment list --status=spam --format=ids)
Removing Temp Data from Database
Expired transients can build up if you have a WooCommerce store. If you need to delete any of this temporary data, you can remove it from your database by running the following command:
Optimizing a Database
If you want to optimize your site database, you can run this command:
Deleting Posts in Trash
If you wanted to delete all posts that are in the trash, only run this command if you have moved posts to the trash, then you could run this command:
wp post delete $(wp post list --post_status=trash --format=ids)
Deleting Posts in Draft Status
If you did need to delete all posts that are set as draft post status, you could run this command;
wp post delete $(wp post list --post_status=draft --format=ids)
Delete Posts With Revisions
If you did want to delete all post revision, then you can run this command;
wp post delete $(wp post list --post_type='revision' --format=ids)
These WP-CLI commands are all very handy for basic housekeeping of your site. These commands in WP-CLI can be used daily or weekly to keep your site optimized and free of bloat.
Related Articles:
About the Author: Luke Cavanagh
Product Operations Manager at Liquid Web. Devoted husband and Tween wrangler. Synthwave enthusiast. Jerry Goldsmith fan. Doctor Who fan and related gubbins.
Our Sales and Support teams are available 24 hours by phone or e-mail to assist.
Latest Articles
How to Edit the PHP Memory for Your WordPress Site via WP Toolkit
Read ArticleWhat is CGI-Bin and What Does it Do?
Read ArticleTop 10 Password Security Standards
Read ArticleTop 10 Password Security Standards
Read ArticleHow to Use the WP Toolkit to Secure and Update WordPress
Read Article