How to Enable WordPress Full Page Caching


If you’re running a WordPress site and want website faster performance but don’t want to use plugins, this guide is for you.

We will show you how to enable full page caching using define('WP_CACHE', true); and a few lines of code. No plugins, no bloat—just clean and simple optimization.

Table of Contents

What Does define('WP_CACHE', true); Do?

This line tells WordPress to enable caching support. It looks for a file called advanced-cache.php in the wp-content/ directory.

If it finds that file, it will try to serve cached content before loading the entire WordPress engine.

Why WordPress Won’t Cache Automatically

Adding WP_CACHE does not cache your site by itself. You need to create the logic to store and serve cached files. Normally, plugins handle this. But you can do it yourself with a few lines of code.

Step 1: Create Your Cache File

Inside wp-content/, create a file called advanced-cache.php. Paste the following code:

 (time() - 3600))) {
    readfile($cache_file);
    exit;
}

ob_start();

This code checks if a cached file exists and is fresh. If yes, it serves it and skips WordPress.

Step 2: Save Output to Cache

At the end of your footer.php file or right after wp_footer(), add:

This saves the full page as an HTML file so it can be loaded next time without running WordPress.

Step 3: Create the Cache Directory

In most cases, the cache folder inside wp-content/ needs to be created manually, but your theme or server environment auto-generates it.

Make a folder inside wp-content/ named cache. Give it write permissions (usually 755 or 775).

Step 4: Set Cache Rules

To avoid caching for logged-in users or specific pages, you can extend the logic. For example:

if (is_user_logged_in()) return;

This helps avoid issues with user-specific content like carts or dashboards.

Step 5: Test Your Cache

Open your site in incognito mode. View the source and refresh twice. You should see faster load times on repeat visits.

Bonus Tips (Without Plugins)

  • Use .htaccess to add browser cache headers.
  • Enable gzip compression via server or .htaccess.
  • Optimize images manually or use WebP.

Final Thoughts

This method works great for blogs, landing pages, or simple business sites. If your site is dynamic consider Redis or a smart invalidation system.

With just a few lines of code, your WordPress site can be faster—no plugin needed!

Reference:

WP_Object_Cache

We provide a wide range of WordPress Speed Optimization Services. Feel free to reach us and also explore our exclusive range of WordPress WooCommerce Plugins.

!!Have a Great Day Ahead!!


Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment