Bypass homepage cache WP
August 7, 2025 · AI Conversations
—
### ✅ Option 1: Set `Cache-Control: no-cache` Header for Homepage
Add this to your `functions.php`:
add_action('send_headers', 'no_cache_homepage');
function no_cache_homepage() {
if (is_front_page() || is_home()) {
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Wed, 11 Jan 1984 05:00:00 GMT");
header("Pragma: no-cache");
}
}
—
### ✅ Option 2: Set a Constant to Signal Caching Plugins (like WP Super Cache, W3TC)
If you're using **WP Super Cache**, it respects `DONOTCACHEPAGE`.
Add:
if (is_front_page() || is_home()) {
define('DONOTCACHEPAGE', true);
}
> Place this **before any output**—typically at the very top of `functions.php` or inside an `init` hook.
Example:
add_action('init', 'bypass_homepage_cache');
function bypass_homepage_cache() {
if (is_front_page() || is_home()) {
define('DONOTCACHEPAGE', true);
}
}
—
### ✅ Option 3: For Page Caching Plugins (e.g., W3 Total Cache, WP Rocket, LiteSpeed Cache)
These may not respect headers unless configured. Still, you can hint with:
add_action('template_redirect', function () {
if (is_front_page() || is_home()) {
header("X-Bypass-Cache: true");
}
});
Then use plugin settings (if available) to exclude based on the header or URL (e.g., `/` or `is_front_page()`).
—
### ✅ Bonus (Cloudflare Users)
If you're using **Cloudflare**, make sure to:
– Create a **Page Rule** to **"Bypass Cache"** for `example.com/`.
—
Let me know which caching plugin you're using (e.g., WP Super Cache, W3TC, WP Rocket, etc.), and I’ll tailor the bypass more specifically.
### ✅ Full Code for `functions.php`
add_action('init', function () {
if (is_front_page() || is_home()) {
define('DONOTCACHEPAGE', true);
}
});
> 🔒 **Important:** This must run early, **before WP Rocket sends any headers**. Placing it in `init` is safe and clean.
—
### ✅ Also (Optional but Recommended):
If you want to ensure logged-out users or specific URLs bypass cache too, you can conditionally disable caching:
add_action('init', function () {
if ((is_front_page() || is_home()) && !is_user_logged_in()) {
define('DONOTCACHEPAGE', true);
}
});
—
### ✅ Confirm it’s working:
1. Open homepage in **Incognito Mode**.
2. Check HTTP headers using browser dev tools or a tool like [websniffer.cc](https://websniffer.cc).
3. You should **not see** the `x-wp-cf-super-cache` or `x-wp-rocket-cache` headers.
—
Let me know if you want to exclude specific page templates or URLs as well—I can extend the logic accordingly.
—
### ✅ Example: Disable WP Rocket cache for Page ID `123`
add_action('init', function () {
if (is_page(123)) {
define('DONOTCACHEPAGE', true);
}
});
> Replace `123` with the actual page ID you want to exclude from caching.
—
### ✅ For Multiple Page IDs
add_action('init', function () {
$excluded_pages = [123, 456, 789]; // Replace with your page IDs
if (is_page($excluded_pages)) {
define('DONOTCACHEPAGE', true);
}
});
—
### 🧠 How to Find a Page ID
– Go to **Pages > Edit** the page in WP Admin.
– Check the URL in the browser:
/wp-admin/post.php?post=123&action=edit
`123` is the page ID.
—
Let me know if you want to exclude pages based on **slug**, **template**, or **custom field** instead — I can provide that logic too.
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add …" to update what will be committed)
(use "git restore …" to discard changes in working directory)
(commit or discard the untracked or modified content in submodules)
modified: packages/community_store (modified content)
no changes added to commit (use "git add" and/or "git commit -a")
modified: packages/community_store (modified content)
means that the **`community_store` submodule** (or subdirectory if not a submodule) has **local changes**, but those changes are not staged for commit.
### 🔍 What’s happening?
This can mean **one of two things**:
—
### ✅ 1. It's a Git **Submodule**
If `packages/community_store` is a Git submodule, this message means the **submodule has new commits** checked out or its contents have changed locally.
To inspect further:
cd packages/community_store
git status
You’ll see whether you've:
– Switched to a different commit
– Pulled in changes
– Made uncommitted edits
To commit the new submodule reference in the parent repo:
cd ~/ddevprojects/concrete-cms
git add packages/community_store
git commit -m "Update community_store submodule"
If you want to discard all local changes to the submodule:
cd packages/community_store
git reset --hard HEAD
cd ..
git add packages/community_store
—
### ✅ 2. It’s Just a Folder (Not a Submodule)
If it's not a submodule but a regular folder, then this message means some files inside `packages/community_store` were edited.
To see what’s modified:
git diff packages/community_store
To stage and commit changes:
git add packages/community_store
git commit -m "Modified community_store package"
Or to discard changes:
git restore --staged packages/community_store
git restore packages/community_store
—
### ✅ To Verify If It's a Submodule
Run:
cat .gitmodules
If you see `packages/community_store` listed, then it is a submodule.
—
Let me know which case applies, and I can guide you step-by-step based on your goal: **commit**, **discard**, or **update**.