How To Stop Page Caching In WordPress

Last Updated on 15th October 2019 by James Thomas
Table of Contents

Caching can be a useful tool for speeding up your website, but it can also be frustrating when you can’t clear the cache properly, or things are being cached that shouldn’t.

Recently, I experienced an issue where a page kept caching, even though there was an exception rule which should have prevented it from caching within the caching plugin I was using, WP Rocket.

To resolve this issue, I wrote some PHP no cache code on the template controlling the blog page. The effect was immediate and the caching on the blog page stopped.

Below is the code snippet you can use if you are experiencing a similar issue.

header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');

This code must be inserted within the PHP template for the page on which you want to disable caching.

Visit our new course

WP The Easy Way

Say goodbye to fancy themes, custom code, too many plugins, code conflicts and
endless WordPress headaches. Build your WordPress website the EASY way.

Say goodbye to fancy themes, custom code, too many plugins, code conflicts and endless WordPress headaches.

Build your WordPress website the
EASY way!