Skip to content

WordPress Clear Cache Command Line

Clearing your WordPress cache via the command line is a fast, efficient way to boost site performance and troubleshoot issues. Using tools like WP-CLI, you can purge object, page, and plugin caches without logging into your dashboard—perfect for developers and advanced users managing multiple sites.

If you’ve ever refreshed your WordPress site only to see old content—or worse, a broken layout—you’ve likely encountered a caching issue. Caching is great for speed, but it can also cause frustrating delays when you’re trying to see your latest changes. While most users clear cache through plugins or hosting dashboards, there’s a faster, more powerful method: using the command line.

Whether you’re a developer managing multiple WordPress sites or a tech-savvy blogger who loves efficiency, knowing how to clear WordPress cache via the command line can save you time and give you more control. This guide will walk you through everything you need to know—from basic WP-CLI commands to advanced server-level cache clearing—so you can keep your site running smoothly.

Key Takeaways

  • WP-CLI is the go-to tool: The WordPress Command Line Interface lets you clear cache quickly with simple commands.
  • Different caches need different commands: Object cache, page cache, and plugin-specific caches each require unique clearing methods.
  • Server-level caching matters: Don’t forget OPcache, Redis, or Varnish—clear them via SSH if used.
  • Automation saves time: Use cron jobs or scripts to auto-clear cache after updates or deployments.
  • Always test after clearing: Check your site’s frontend and backend to ensure everything works correctly.
  • Backup first: While rare, clearing cache can expose hidden issues—always have a recent backup.

Quick Answers to Common Questions

How do I clear WordPress cache using WP-CLI?

Use wp cache flush to clear object cache and wp transient delete --all to remove transients. For plugin caches, use commands like wp w3-total-cache flush all.

Can I clear cache without WP-CLI?

Yes, you can use SSH to run PHP commands or manually delete cache folders via FTP. But WP-CLI is faster and more reliable.

Does clearing cache affect my site’s performance?

Temporarily, yes—your site may load slower until the cache rebuilds. But it’s necessary after updates or troubleshooting.

How often should I clear cache?

Only when needed—after updates, design changes, or performance issues. Avoid over-clearing, as it can hurt speed.

What if WP-CLI isn’t installed?

You can install it manually from wp-cli.org or ask your host. Many managed hosts like Bluehost include it by default.

Why Clear Cache from the Command Line?

Clearing cache through the WordPress admin or a plugin is easy, but it’s not always the fastest or most reliable method—especially on high-traffic sites or when the admin dashboard is slow or inaccessible. That’s where the command line shines.

Using the command line, you can clear cache instantly, automate the process, and manage multiple sites from a single terminal session. It’s especially useful for developers working on staging environments, performing bulk updates, or debugging performance issues. Plus, it reduces reliance on plugins, which can sometimes conflict or fail.

Benefits of Command Line Cache Clearing

  • Speed: No need to load the WordPress admin—just run a command and go.
  • Reliability: Works even if your site is partially broken or the admin is down.
  • Automation: Easily integrate cache clearing into deployment scripts or cron jobs.
  • Granular control: Target specific types of cache (object, page, transients) without affecting others.

Getting Started with WP-CLI

WP-CLI (WordPress Command Line Interface) is a powerful tool that lets you manage WordPress sites from the terminal. It’s pre-installed on many managed WordPress hosts like WP Engine and Bluehost, or you can install it manually.

To check if WP-CLI is installed, open your terminal and run:
wp --info
If it’s installed, you’ll see version details and configuration info. If not, visit the official WP-CLI website to install it.

Once WP-CLI is ready, navigate to your WordPress installation directory:
cd /path/to/your/wordpress
This is usually your public_html or www folder, depending on your hosting setup.

Basic WP-CLI Cache Commands

WP-CLI includes built-in commands for managing cache. Here are the most useful ones:

To clear the object cache (used by plugins like Redis or Memcached):
wp cache flush
This removes all cached objects stored in memory.

To clear transients (temporary data stored in the database):
wp transient delete --all
Transients often hold cached query results or API responses.

To clear the full page cache (if using a plugin like W3 Total Cache or WP Super Cache):
wp plugin cache flush
Note: This command works only if the plugin supports WP-CLI. Most popular caching plugins do.

Many WordPress sites rely on caching plugins to improve performance. While some offer their own WP-CLI commands, others require specific syntax.

W3 Total Cache

W3 Total Cache is one of the most popular caching plugins. To clear all caches via command line:
wp w3-total-cache flush all
You can also flush specific caches:
wp w3-total-cache flush minify
wp w3-total-cache flush db
wp w3-total-cache flush object

WP Super Cache

For WP Super Cache, use:
wp super-cache flush
This clears all cached pages generated by the plugin.

LiteSpeed Cache

If your host uses LiteSpeed servers, the LiteSpeed Cache plugin is common. Clear it with:
wp litespeed-cache purge all
You can also purge specific URLs:
wp litespeed-cache purge url https://yoursite.com/page

Redis Object Cache

If you’re using Redis for object caching, first ensure the Redis Object Cache plugin is active. Then run:
wp redis flush
This clears the Redis cache instantly.

Server-Level Cache Clearing

Sometimes, cache isn’t stored in WordPress at all—it’s handled at the server level. If you’re using OPcache, Varnish, or a CDN, you’ll need to clear those separately.

Clearing OPcache

OPcache stores compiled PHP scripts in memory. To clear it via command line:
wp eval 'opcache_reset();'
This runs a PHP function to reset the OPcache. Note: This only works if OPcache is enabled and the function is available.

Clearing Varnish Cache

Varnish is a powerful HTTP accelerator. If your host uses Varnish (common on high-performance setups), you can purge it with:
wp http post http://localhost:6081/purge
Or use curl directly:
curl -X PURGE http://yoursite.com
Check with your host for the correct Varnish purge method.

Clearing CDN Cache

CDNs like Cloudflare or BunnyCDN cache your site globally. While they don’t have direct WP-CLI integration, you can use their APIs. For example, to purge Cloudflare via command line:
curl -X POST "https://api.cloudflare.com/client/v4/zones/YOUR_ZONE_ID/purge_cache" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'

Replace YOUR_ZONE_ID and YOUR_API_TOKEN with your actual credentials.

Automating Cache Clearing

Manually clearing cache gets old fast—especially if you update your site regularly. Automation is the answer.

Using Cron Jobs

You can schedule regular cache clearing using cron. For example, to clear object cache every day at 2 AM, add this to your crontab:
0 2 * * * cd /path/to/wordpress && wp cache flush
Use crontab -e to edit your cron jobs.

Deployment Scripts

If you use Git or CI/CD pipelines, include cache clearing in your deployment script:
wp cache flush && wp transient delete --all && wp w3-total-cache flush all
This ensures a clean cache after every update.

Best Practices and Tips

Clearing cache via command line is powerful, but it comes with responsibility. Follow these best practices to avoid issues.

Always Test After Clearing

After clearing cache, visit your site and check key pages. Look for missing styles, broken images, or slow loading. If something’s off, it might be a plugin conflict or a misconfiguration.

Use Staging First

If you’re testing new commands or scripts, do it on a staging site first. This prevents downtime or errors on your live site.

Monitor Performance

Use tools like Query Monitor or New Relic to see how cache clearing affects performance. Sometimes, clearing too often can hurt speed—find the right balance.

Combine with Other Optimizations

Clearing cache is just one part of performance tuning. Pair it with a fast, SEO-optimized WordPress theme and reliable WordPress hosting for best results.

Keep WP-CLI Updated

Run wp cli update regularly to get the latest features and security fixes.

Conclusion

Clearing WordPress cache from the command line is a skill every serious WordPress user should have. It’s faster, more reliable, and gives you deeper control over your site’s performance. Whether you’re using WP-CLI to flush object cache, purge plugin caches, or clear server-level systems like OPcache or Varnish, the command line puts power at your fingertips.

Start with simple commands like wp cache flush and wp transient delete --all, then explore plugin-specific options and automation. With practice, you’ll be able to manage cache across multiple sites with just a few keystrokes.

Remember: cache exists to help your site run faster—so don’t disable it entirely. Instead, learn when and how to clear it wisely. Combine command line tools with smart hosting, a well-optimized theme, and regular maintenance for a site that’s both fast and reliable.

Frequently Asked Questions

What is WP-CLI?

WP-CLI is a command-line tool for managing WordPress sites. It lets you run tasks like updating plugins, importing content, and clearing cache without using the admin dashboard.

Is it safe to clear cache via command line?

Yes, as long as you use the correct commands. Always test on a staging site first and ensure you have a recent backup.

Can I clear cache for a specific page only?

Some plugins support this. For example, LiteSpeed Cache allows wp litespeed-cache purge url https://yoursite.com/page to target a single URL.

Why isn’t my site updating after clearing cache?

You might have server-level caching (like Varnish or CDN) that wasn’t cleared. Also check browser cache—use Ctrl+F5 to hard refresh.

Do all caching plugins support WP-CLI?

Most popular ones do, including W3 Total Cache, WP Super Cache, and LiteSpeed Cache. Check the plugin’s documentation for WP-CLI support.

How do I clear cache on shared hosting?

If you have SSH access, use WP-CLI. If not, check your hosting control panel (like cPanel) for cache management tools or contact support.