If you run a WordPress site and have switched on Cloudflare APO (Automatic Platform Optimization), or are about to, this walks you through making it actually serve your pages from Cloudflare’s edge. A common week looks like this: APO is on, the dashboard says it is active, yet most requests still reach your server and pages feel no faster. The usual cause is a cookie or a query string that makes Cloudflare skip the cache, or another cache layer fighting with APO. The fix is to confirm the plugin is talking to Cloudflare, read three response headers with curl, and remove whatever triggers the bypass. You finish with anonymous visitors served from the edge and logged-in or shopping visitors still served fresh from WordPress.
What you’ll accomplish
- APO enabled through the official Cloudflare WordPress plugin, with the
cf-edge-cacheheader present on every page. - A repeatable curl test that tells a cache hit from a bypass in a few seconds.
- The cookie or query string that was lowering your hit ratio identified and dealt with.
- No other full-page cache or Cloudflare rule overriding APO’s privacy bypasses.
- On cPanel, real visitor IP addresses in your logs and security tools again.
Prerequisites
- A single WordPress site (APO’s plugin does not support WordPress multisite).
- The domain on Cloudflare with the site’s DNS records proxied (orange cloud). Cloudflare’s setup steps assume its nameservers.
- APO available on the zone. On the Free plan it is a paid add-on bought under Speed > Settings > Content Optimization; on Pro and higher plans it is included.
- WordPress administrator access, and a terminal with
curl. Shell access to the server helps for the cPanel section.
How it works
APO uses Cloudflare Workers, small programs running on Cloudflare’s servers, to cache the HTML of your WordPress pages at the edge, the Cloudflare location closest to each visitor. Cloudflare does not document which internal store holds that HTML, so treat it as Cloudflare’s edge cache and judge it by the headers below.
According to Cloudflare’s APO documentation, APO caches a page only when all of these hold:
- The request is a
GETorHEADthat asks for HTML, and the origin returns status 200 withContent-Type: text/html. - The WordPress plugin sent
cf-edge-cache: cache,platform=wordpress. It sendscf-edge-cache: no-cacheinstead to logged-in users. - No cookie on the request starts with a bypass prefix:
wp-,wordpress,comment_,woocommerce_,edd_,jetpack,xf_,wpsc_,ecwid,ec_,bookly,yith_wcwl_session_oryith_wrvp_. - The URL has no query string, or only parameters from Cloudflare’s marketing allowlist (
utm_source,utm_medium,utm_campaign,fbclid,gclid,_ga,refand a few others). - The path is not excluded (checkout,
wp-cron.php, feeds), and no rule says to bypass.
When a request fails any test, Cloudflare fetches it from your server and marks it cf-cache-status: DYNAMIC. That is how logged-in and cart pages stay private. A cached page stays at the edge for up to 30 days. When you publish, the plugin purges the affected URLs, and Cloudflare says the change takes effect within about 30 seconds. APO also ignores your origin’s Cache-Control header for edge caching, though visitors’ browsers still receive it.
Step-by-step
1. Check the plugin is installed and current. The Cloudflare dashboard only detects the plugin from version 3.8.2, and features such as cache by device type need 4.4.0 or later.
wp plugin list --name=cloudflare --fields=name,status,version
Example output:
+------------+--------+---------+
| name | status | version |
+------------+--------+---------+
| cloudflare | active | 4.14.1 |
+------------+--------+---------+
No row means the plugin is missing. Install it from Plugins > Add New by searching for Cloudflare.
2. Connect the plugin and turn APO on. In the Cloudflare dashboard, create an API token from the WordPress template under Account API tokens. In WordPress, open the Cloudflare plugin’s settings, sign in with your email and the token, and choose Save API Credentials. Apply Recommended Cloudflare Settings for WordPress, then switch Automatic Platform Optimization on. The APO card in the Cloudflare dashboard should now list your hostname.
3. Pause other page caches for the first test. Cloudflare recommends turning off WP Rocket, W3 Total Cache and similar plugins while you set up APO, then clearing their caches. A copy served by another cache can lack the cf-edge-cache header, and APO will not cache it. You can turn them back on once the steps below pass.
4. Read the three headers. Send the request twice. The accept: text/html header makes curl behave like a browser, so the result does not depend on the URL shape.
curl -svo /dev/null -H 'accept: text/html' https://www.example.com/ 2>&1 | grep -iE 'cf-cache-status|cf-apo-via|cf-edge-cache'
Example output, second run:
< cf-cache-status: HIT
< cf-apo-via: tcache
< cf-edge-cache: cache,platform=wordpress
HIT with cf-apo-via: tcache is the result Cloudflare documents as APO working. Cloudflare’s own sample output also shows cf-apo-via: cache, so treat either as a hit. A first run often shows MISS, which means the edge had no copy and fetched one. If cf-edge-cache is missing, the plugin is not adding its header, or another cache answered first: go back to step 3. If cf-cache-status stays DYNAMIC, read the cf-apo-via value, which Cloudflare uses to show why the request bypassed, then move to step 5.
5. Test the bypasses on purpose. Prove that a logged-in style cookie bypasses, and that a marketing parameter does not.
curl -svo /dev/null -H 'accept: text/html' -H 'Cookie: wordpress_test_cookie=WP%20Cookie%20check' https://www.example.com/ 2>&1 | grep -i 'cf-cache-status'
curl -svo /dev/null -H 'accept: text/html' 'https://www.example.com/?utm_source=newsletter' 2>&1 | grep -i 'cf-cache-status'
curl -svo /dev/null -H 'accept: text/html' 'https://www.example.com/?color=blue' 2>&1 | grep -i 'cf-cache-status'
Example output:
< cf-cache-status: DYNAMIC
< cf-cache-status: HIT
< cf-cache-status: DYNAMIC
That pattern is correct. If the cookie request returns HIT, a rule other than APO is caching past the bypass. Treat that as urgent and go to step 7.
6. Find the cookie behind a low hit ratio. Your curl tests carry no cookies, so they can look perfect while real visitors bypass. Open the site in a private browser window, browse three or four pages as a visitor would, then open developer tools: Application > Cookies in Chrome, Storage > Cookies in Firefox. Any cookie whose name starts with a prefix from the list above makes every later request from that visitor skip the edge. You can also see what a page sets with curl:
curl -s -o /dev/null -D - -H 'accept: text/html' https://www.example.com/product/blue-mug/ | grep -i '^set-cookie'
Example output:
set-cookie: woocommerce_recently_viewed=812; path=/; secure; HttpOnly
Here a WooCommerce recently-viewed feature sets a woocommerce_ cookie on a plain product view. From then on, that shopper gets no edge hits. Remove or replace the feature that sets the cookie, or accept the bypass if the feature matters more. Visiting wp-login.php also sets wordpress_test_cookie, so staff who test while logged out still bypass. Always test in a fresh private window.
7. Check Cloudflare rules that change APO’s behaviour. Under Caching > Cache Rules and any legacy Page Rules, list every rule that matches your HTML pages. Cloudflare documents how these interact with APO:
- Cache Everything makes APO cache pages with any query string. The plugin’s automatic purge then only clears URLs without query strings, and responses are served even when the request sends
cache-control: no-cache. A rule like this can also cache a WooCommerce cart for other shoppers. Remove it from HTML paths, or scope it with explicit bypasses as described in fixing a stale WooCommerce cart under APO. - Bypass returns
cf-apo-via: origin,page-rulesand is the right tool for paths that must never be cached. - Bypass Cache on Cookie (Business and Enterprise plans) adds your own cookie names to APO’s default list.
- Edge Cache TTL replaces APO’s 30 days for the matched URLs.
Any change to these rules needs a cache purge before it takes effect.
8. Decide on cache by device type. If your theme or a plugin sends different HTML to phones, tablets and desktops, turn on Cache by device type on the APO card or in the plugin. Cloudflare then sends a CF-Device-Type header (mobile, tablet or desktop) to your server and keeps one copy per type. A responsive theme that sends the same HTML to everyone does not need it. Changing this setting empties the cache.
9. Check purging on publish. Edit a published post and change one word. The plugin purges the post itself, its category and tag archives, the author page, the home page, the posts page, the first three pages of /page/N/, and the feeds. Switching or customizing the theme purges everything. Pages that show the post elsewhere, such as a custom landing page or page four of an archive, are not purged. Add those URLs with the plugin’s cloudflare_purge_by_url filter in a small must-use plugin:
<?php
// wp-content/mu-plugins/apo-extra-purge.php
add_filter('cloudflare_purge_by_url', function ($urls, $post_id) {
$urls[] = home_url('/latest-news/');
return $urls;
}, 10, 2);
Then run step 4’s curl against /latest-news/ after your next edit. Expected: MISS on the first request, HIT on the second.
On a cPanel server
Most cPanel servers add three things to watch.
Pick one full-page cache. On a LiteSpeed server, the LiteSpeed Cache plugin (LSCache) stores full pages at the origin, and APO stores them at the edge. LSCache is not on Cloudflare’s list of APO-compatible plugins. Running both means two purges on every publish and a copy that can be served without cf-edge-cache. If APO is your page cache, turn off LSCache’s page caching in its Cache settings and keep its image and object-cache features. If LSCache is your page cache, leave APO off. How the two compare is covered in LiteSpeed Cache vs Cloudflare APO vs object cache.
Restore the real visitor IP. Behind Cloudflare, Apache sees Cloudflare’s addresses, so fail2ban-style blocks, Imunify360 and WordPress security plugins all see the wrong client. On Apache, install mod_remoteip through EasyApache 4 and trust CF-Connecting-IP only from Cloudflare’s published ranges. The full setup is in restoring real visitor IPs with mod_remoteip. On LiteSpeed, use its Use Client IP in Header setting instead. Check the module:
apachectl -M 2>/dev/null | grep remoteip
Expected output:
remoteip_module (shared)
Check origin headers and cookies. Because APO ignores origin Cache-Control at the edge, a no-cache header from a plugin will not stop APO caching. To keep a page out, the plugin must send cf-edge-cache: no-cache, or you add a Cloudflare Bypass rule. Cookies matter for the reason in step 6, not because of the header itself.
Validate it works
Run this loop against three public pages, in a fresh shell with no cookies:
for u in / /about/ /blog/; do printf '%s ' "$u"; curl -svo /dev/null -H 'accept: text/html' "https://www.example.com$u" 2>&1 | grep -i 'cf-cache-status'; done
Example output:
/ < cf-cache-status: HIT
/about/ < cf-cache-status: HIT
/blog/ < cf-cache-status: HIT
Then log in to WordPress in a normal browser window and view the home page with developer tools open. Uncheck Disable cache in the Network tab first; while it is checked, Chrome sends Cache-Control: no-cache. The document request should show cf-cache-status: DYNAMIC and cf-edge-cache: no-cache. Finally, add a product to a cart in a private window and confirm the cart page also shows DYNAMIC.
Troubleshooting
- The dashboard says the plugin is not detected. The plugin is older than 3.8.2, another cache is serving pages without
cf-edge-cache, or WordPress lives on a subdomain while the plugin checks the apex. Update the plugin, purge the other cache, and enable APO for the right hostname on the APO card. - Browser shows
BYPASS, curl showsHIT. Developer tools with Disable cache checked sendno-cache. Uncheck it and reload. - Testing tools show
DYNAMICorMISSevery time. Some tools send noAcceptheader. Add-H 'accept: text/html'to reproduce a browser request. - Forms fail with an expired-link or security-check error. A WordPress nonce, a one-time token in the form, is valid for at most 24 hours, and the cached page may be weeks old. Add a Cache Rule for the form’s URL with an Edge TTL of 10 hours, so the token is always fresh enough.
- Edits still show old content after a minute. Confirm the plugin still has a valid API token, then purge the URL from the plugin or the dashboard.
When this is the wrong approach
APO helps most on content sites where most visitors are anonymous. It does little on a membership site, a learning platform or a busy store where most visitors are logged in or carry a cart, because those requests bypass by design. A server-side page cache plus an object cache usually does more there. It is also wrong for multisite, which the plugin does not support, and for Enterprise subdomain setups where www sits in a different zone from the apex. If you only need static files on the CDN, Cloudflare’s normal caching covers that without APO.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.