Skip to content
Arrow keys to move, Enter to open, Esc to closeAll results
Performance · Guides

How to Set Up Cloudflare for WordPress

A practical guide to putting Cloudflare in front of WordPress: nameservers, SSL modes, safe caching rules, WooCommerce bypasses, APO, security and a rollback plan.

Written by
WPresident Editorial
Topic
Performance

You add Cloudflare to a WordPress site, flip the switch, and one of three things happens. The site gets faster and quieter and you forget about it. Or the browser reports ERR_TOO_MANY_REDIRECTS and every page becomes a loop. Or everything looks fine for a week, until a customer sees a stranger’s cart, an editor finds the admin bar missing, or the contact form stops sending mail because a DNS record did not make the trip. All three are the same setup. The difference is whether the person who made the change understood what Cloudflare was now doing to each request.

The most important idea is this: Cloudflare is a reverse proxy, and turning it on means a new machine now answers your visitors on behalf of your server. That machine can do useful things. It can answer DNS, end the HTTPS connection close to the visitor, refuse bad traffic before it reaches PHP, and hand back stored copies of files and pages without waking WordPress at all. But it only knows what you tell it. It does not know that the admin area is private, that a cart page is personal, or that your server redirects HTTP to HTTPS. Every setting in this guide is really an answer to one of three questions: what may be stored and served without asking your server, what should be stopped before it reaches your server, and how should Cloudflare talk to your server when it does have to ask.

Those questions set the order of this tutorial. First the plumbing: auditing DNS, moving nameservers and choosing which records go through the proxy. Then the connection: SSL/TLS modes, the redirect loop, and making the origin aware of the proxy. Then caching, where most of the speed and most of the risk live, including WooCommerce, logged-in users and APO. After that come the features that deserve caution, the security tools, a purge strategy that works with a caching plugin, and finally testing and rollback.

Set one expectation early. Cloudflare will not make a slow origin fast. A cache hit is fast because the work never happens; a cache miss still reaches PHP and the database exactly as before. If your uncached pages take several seconds because of a heavy plugin or an underpowered server, Cloudflare hides that on cached pages and exposes it everywhere else, including the admin area and checkout. Treat it as a layer on top of a healthy site, not a substitute. The same goes for security: a proxy reduces the junk that reaches your server, but it does not patch a vulnerable plugin.

Two practical notes. Cloudflare changes its dashboard regularly, so this guide describes settings by name and purpose and says what to verify in the documentation; plan limits and product names change too. And before you begin, check whether your host already puts its own CDN or Cloudflare integration in front of the site. Several managed hosts do, and a second proxy layer on top of theirs can create the loops and double caches described later. Ask support first.

The method that keeps all of this safe is deliberately boring: change one layer at a time, verify with real response headers after each change, and keep a rollback path open until the site has run cleanly through a full publishing and checkout cycle.

Key points

  • Cloudflare is a reverse proxy: only records with the orange cloud get caching, the WAF and rules, while grey-cloud records are plain DNS.
  • Move DNS first with every record set to DNS only, verify the site and mail, then turn the proxy on gradually so you know which change caused which problem.
  • Use Full (strict) SSL with a valid certificate on the origin; Flexible mode combined with an HTTPS redirect on your server is the classic cause of redirect loops.
  • Cloudflare caches static files by extension and does not cache HTML by default, so any HTML caching needs explicit rules that bypass admin, login, logged-in and cart traffic.
  • Make the origin proxy-aware: restore real visitor IPs, detect HTTPS correctly, and where possible accept web traffic only from Cloudflare.
  • Keep one owner for purging, either your caching plugin’s Cloudflare integration or APO, and confirm every change with the cf-cache-status response header.
  • Plan the rollback before you need it: keep an exported DNS copy, prefer a publicly trusted origin certificate, and know how to grey-cloud or pause the site.

What Cloudflare does when it sits in front of WordPress

Before the change, a visitor’s browser asks DNS for your domain and gets your server’s IP address. It connects straight to that server, which negotiates HTTPS, runs PHP, queries MySQL and sends back a page. Every request, for every image, stylesheet and script, lands on a machine you pay for and that has a finite number of PHP workers.

After the change, DNS answers with Cloudflare’s addresses instead. The visitor connects to a Cloudflare data center near them, and the HTTPS connection ends there, using a certificate Cloudflare holds for your domain. Cloudflare then decides, in order, whether the request should be refused or challenged, whether it can be answered from its own storage, and, only if neither applies, whether to open a second, separate connection to your server and fetch the response.

That two-connection design is the source of nearly every Cloudflare problem. There are two TLS sessions, which is why SSL modes exist. The origin sees Cloudflare’s IP address instead of the visitor’s, which is why logs, security plugins and rate limiters need adjusting. A copy stored at the edge can outlive a change on the origin, which is why purging matters. And a response stored for one visitor may be handed to the next, which is why cookies and logged-in users need explicit handling.

It helps to separate the products bundled under one name. Cloudflare DNS is the authoritative DNS service, active once you move your nameservers. The proxy and CDN are what the orange cloud switches on for a record. TLS termination, the WAF, rate limiting and bot tools run inside the proxy. The Rules products, including Cache Rules, change behaviour per URL or request condition. APO is a separate WordPress-specific caching product, covered later.

What does the cache change for WordPress specifically? A typical page view triggers one HTML request and often dozens of static requests. Static files are the easy win: they are identical for every visitor, they never need PHP, and Cloudflare caches them by default. The HTML is the hard part. It is what costs you CPU, and by default Cloudflare does not store it, for good reason. Most of this guide is about getting from “static files are cached” to “public HTML is cached too, and nothing private ever is”.

The path of one request through Cloudflare

  1. DNS answerThe domain resolves to Cloudflare addresses, not to your server.
  2. Nearest data centerThe browser connects and the visitor-side HTTPS session ends here.
  3. Security checksWAF, rate limits and bot rules can block or challenge the request.
  4. Cache lookupA stored copy that is still valid is returned without touching your server.
  5. Origin fetchOn a miss, Cloudflare opens its own connection to your server.
  6. Response and storageThe reply goes to the visitor and is stored only if the rules allow it.
A proxied request is answered by Cloudflare first and only reaches your server when nothing earlier in the chain can handle it.

Audit your DNS and decide what gets proxied

Cloudflare’s setup wizard scans your existing DNS and offers to import what it finds. Treat that as a first draft, not an inventory. A scan checks for common record names and can miss records on unusual subdomains, and it knows nothing about records you forgot you had. The safe version of this step happens before you touch Cloudflare: open your current DNS host and write down, or export as a zone file if the provider allows it, every record in the zone.

Group them by purpose. Web records: the apex (example.com), www, and subdomains such as staging or shop. Mail records: MX, the TXT records for SPF, DKIM and DMARC, and mail host names. Verification records: TXT or CNAME entries that prove ownership to Google, Microsoft or your email provider. Service records: SRV, CAA and anything pointing at a third-party app. After the import, compare the two lists line by line. A missing MX record means mail stops the moment the nameservers change. A missing SPF or DKIM record means mail keeps flowing and quietly lands in spam.

Now decide what is proxied. The orange cloud (proxied) and the grey cloud (DNS only) are set per record, not per site. Proxying makes Cloudflare answer with its own addresses and apply its features. Only web traffic can be proxied: HTTP and HTTPS, on a limited set of ports. Mail servers, SSH, FTP, database ports and anything non-web must stay DNS only, or they will simply stop working. The same applies to a mail host name. If mail.example.com points to your web server’s IP and is grey, it also publishes that IP to the world, which undermines the point of proxying the website.

That leads to the origin IP. Proxying hides your server’s address only as long as nothing else reveals it. Typical leaks are a grey-clouded subdomain on the same server, mail sent directly from the server (the address appears in message headers), archived DNS history and certificate lookup tools. You cannot prevent all of it, so the durable defence is making the origin refuse requests that do not come from Cloudflare, covered in the origin-side section.

Last, ask the awkward question: should this zone use a full setup at all? A full setup, where Cloudflare becomes your DNS provider, is the standard route and the one this guide follows. A partial setup keeps DNS where it is and routes only chosen hostnames through Cloudflare using a CNAME, but it is offered only on higher plans, so verify current availability. Also note who controls the registrar; many migrations stall because the only person with access is away.

Proxied versus DNS only, record by record

Proxied (orange cloud)DNS only (grey cloud)
What DNS returnsCloudflare addressesYour own server address
CDN, WAF and rules applyYes, for HTTP and HTTPSNo, traffic bypasses Cloudflare
Origin IP in DNS answersHiddenPublic
Record typesWeb hostnames: A, AAAA, CNAMEAny type, including MX and TXT
TTLAutomatic and shortYou choose
Right forThe website and web subdomainsMail hosts, SSH, FTP and verification records
The same hostname behaves very differently depending on the cloud icon next to its record.

Change nameservers, mind the TTLs and expect a wait

With the audit done, add the domain in the Cloudflare dashboard and let it import records. Review them against your list. For this first pass, set every web record to DNS only, grey cloud. It seems backwards, but it separates two risky changes: moving DNS and putting a proxy in front of the site. If you do both at once and something breaks, you will not know whether the culprit is a missing record, a TLS mismatch or a cache rule. With everything grey, only who answers DNS changes.

Cloudflare then shows two nameservers assigned to your zone. At your registrar (which may differ from your DNS host), replace the existing nameservers with exactly those two and remove the old ones. Two details trip people up. If the domain uses DNSSEC, remove the DS record at the registrar or switch DNSSEC off before changing nameservers, because a mismatch makes validating resolvers reject the domain; Cloudflare’s documentation says to re-enable it from Cloudflare once the zone is active. And the change must be made at the registrar, not in the old DNS host’s zone editor, because the registrar publishes the delegation.

Now the timing. The delegation lives in the parent zone, the top-level domain’s servers, and resolvers around the world cache it for a TTL you do not control. Cloudflare’s documentation tells you to allow up to 24 hours. Many zones activate within hours, but plan for a day and avoid changing just before a launch or sale. While you wait, the zone shows a pending status, and some visitors reach the old DNS host while others reach Cloudflare. That is harmless only if both sides hold the same records, which is why the audit matters. Do not edit records at the old host during the wait without mirroring the change in Cloudflare.

The record TTLs you do control matter for a different reason. If you expect to change IP addresses soon, lower those TTLs at the old host a day or two beforehand. After activation, proxied records show an automatic, short TTL, because Cloudflare can change the addresses it returns; grey records keep your setting.

When Cloudflare emails that the zone is active and the dashboard agrees, verify it yourself instead of trusting the status:

$ dig NS example.com +short
$ dig MX example.com +short
$ dig TXT example.com +short

The first command should list two Cloudflare nameservers, and the other two should match the records you inventoried. Send a test email, load the site, then check the certificate status under SSL/TLS before proxying anything. Cloudflare issues an edge certificate for proxied hostnames, usually quickly but not instantly, and proxying before it is active gives visitors certificate errors.

A nameserver move, from preparation to proxy

Days beforeExport or write down every record, turn off DNSSEC at the registrar if it is on, and lower TTLs on records you may change.
Day 0, CloudflareAdd the domain, compare imported records to your list, and set web records to DNS only.
Day 0, registrarReplace the old nameservers with the two Cloudflare assigned ones.
Waiting periodThe zone shows pending; resolvers move over gradually, so allow up to a day.
Zone activeCheck nameservers with dig, test mail and the site, confirm the edge certificate is active.
After thatTurn the proxy on one hostname at a time, then work through SSL and caching.
Separating the DNS move from the proxy switch means every failure has only one possible cause.

SSL/TLS modes and the redirect loop trap

A proxied site has two encrypted-or-not connections: visitor to Cloudflare, and Cloudflare to your origin. The visitor leg is handled by Cloudflare’s edge certificate. The SSL/TLS mode controls only the second leg, and picking the wrong one is the most common reason a new Cloudflare setup fails on day one.

Cloudflare’s documentation describes the modes like this. Off sends everything as plain HTTP. Flexible lets visitors use HTTPS but connects to your origin over plain HTTP, so the origin needs no certificate at all. Full connects to the origin over HTTPS when the visitor used HTTPS, but does not check the certificate, so a self-signed certificate passes. Full (strict) does the same and validates the certificate, which can come from a public authority such as Let’s Encrypt or from the free Cloudflare Origin CA. A further strict option always connects over HTTPS regardless of the visitor’s protocol. Cloudflare recommends Full or Full (strict) wherever the origin can support them, and Full (strict) is the right target for almost every WordPress site.

Now the trap. Suppose the zone is on Flexible, and your server, a security plugin or your host forces HTTP to HTTPS. The visitor requests the HTTPS page. Cloudflare asks the origin over HTTP. The origin answers with a redirect to the HTTPS address. Cloudflare passes that redirect to the browser, the browser asks for the HTTPS page again, Cloudflare again asks the origin over HTTP, and the loop continues until the browser gives up with ERR_TOO_MANY_REDIRECTS. The visitor-facing site and the origin each look correct in isolation; only the combination loops.

The proper fix is to give the origin a certificate and move up to Full (strict). Many hosts offer a free certificate with one click, and for hosts that do not, Let’s Encrypt or the Cloudflare Origin CA will do. A weaker interim fix is to tell WordPress that the connection is already secure when Cloudflare says so, covered in the origin-side section, but that leaves the second leg unencrypted and should be a stopgap.

Choose the origin certificate with rollback in mind. A Cloudflare Origin CA certificate is trusted only by Cloudflare. If you later set records to DNS only or pause Cloudflare, browsers will reject that certificate and visitors see security warnings. A publicly trusted certificate keeps working in both states, which makes the exit path far safer.

Two more settings belong here. Newer zones may use Automatic SSL/TLS, which scans the origin and picks the most secure mode it can verify, upgrades gradually and never moves to a less secure mode, so check which mode is actually active and set it explicitly if you want predictability. Finally, treat HSTS as a one-way door: enable it only after every hostname works over HTTPS, and think hard before adding preload, which is slow to undo.

Which SSL/TLS mode fits your origin

What does your origin server present on port 443?
A certificate from a public authority, or one from Cloudflare Origin CAUse Full (strict). Prefer a public certificate if you may ever need to turn the proxy off.
A self-signed or expired certificateReplace it. Full works as a short bridge but does not validate, so it is not a destination.
No HTTPS at allInstall a certificate first. Flexible leaves the second leg unencrypted and loops if the origin redirects to HTTPS.
Pick the strictest mode the origin can satisfy, and treat Flexible as a temporary bridge at best.

Make the origin proxy-aware: visitor IPs, HTTPS detection and lockdown

Once traffic flows through Cloudflare, your server sees a different world. Every connection comes from a Cloudflare address, the visitor’s real address arrives in a header, and the HTTPS that WordPress cares about may have ended one hop earlier. Three adjustments make the origin behave.

First, restore the real visitor IP. Cloudflare passes it in the CF-Connecting-IP header. Until your web server or application reads that header, access logs, security plugins and login limiters see only Cloudflare addresses. A lockout rule can then ban a Cloudflare address and block thousands of innocent visitors at once. Many hosts configure this for you; if yours does not, use the real-IP support in the web server. For Nginx that is the realip module:

real_ip_header CF-Connecting-IP;
# Add one set_real_ip_from line for every range on Cloudflare's published IP list, for example:
set_real_ip_from 173.245.48.0/20;

For Apache the equivalent directives are RemoteIPHeader and RemoteIPTrustedProxy in mod_remoteip. Always copy the current ranges from Cloudflare’s IP ranges page and refresh them occasionally, because they do change. Security plugins usually have a setting for which header to trust; point it at CF-Connecting-IP only if your origin accepts requests from Cloudflare alone, otherwise anyone can forge the header.

Second, make WordPress detect HTTPS. When Cloudflare connects over plain HTTP (Flexible mode), WordPress sees an insecure request, builds http links and may redirect. Cloudflare sets X-Forwarded-Proto to the visitor’s protocol, and a common fix goes in wp-config.php above the line that says to stop editing:

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
	$_SERVER['HTTPS'] = 'on';
}

Use it as a bridge, and only when the origin is reachable through Cloudflare alone, since any client could otherwise send that header. Then confirm WordPress itself is configured for HTTPS addresses:

$ wp option get home
$ wp option get siteurl

Both should begin with https. If they do not, fix that deliberately rather than relying on redirects.

Third, lock the origin. Proxying hides your IP only until someone finds it, and an attacker who reaches the origin directly skips the WAF, rate limits and cache entirely. The options, from simple to strong: firewall ports 80 and 443 to accept only Cloudflare’s published ranges; Authenticated Origin Pulls, where the origin requires a client certificate that only Cloudflare presents; or Cloudflare Tunnel, where a small connector on your server makes an outbound connection and nothing listens publicly at all. Whichever you choose, schedule an update for the IP ranges, because an out-of-date allow list turns into an outage the day Cloudflare adds a range.

What Cloudflare caches by default, and what it does not

Cloudflare’s default is conservative and it is worth knowing exactly where the line sits. By default it caches based on the file extension in the URL, not on the content type the server reports. Images, fonts, stylesheets, scripts, PDFs and archives are on the list. HTML and JSON are not, which means a stock WordPress page is fetched from your origin every time, even though your theme’s CSS and JavaScript are served from the edge. It is the first thing to check when someone says Cloudflare is not helping.

The origin’s headers can also veto caching even for eligible files. Cloudflare will not store a response whose Cache-Control says private, no-store, no-cache or max-age=0, nor one that sets a cookie with Set-Cookie, nor any request that is not a GET. A response marked public with a positive max-age, or carrying a future Expires date, is eligible. In practice that means a plugin or server rule that adds the wrong header to static files can silently disable caching for them, and a stray Set-Cookie on a normal page keeps it out of the cache even after you tell Cloudflare to cache HTML.

Two other concepts decide how well the cache works. The first is the cache key, the identity of a stored object. By default it is based on the full URL, including the query string, so a page reached with a tracking parameter on the end is cached separately from the same page without it. Marketing links with unique parameters can therefore produce many near-empty cache entries and a poor hit rate. The finer controls for ignoring or reshaping query strings are tied to certain plans, so check what yours allows before designing around them. The second is the difference between edge TTL (how long Cloudflare keeps a copy) and browser TTL (how long the visitor’s own browser keeps it). You can purge the first; you can never reach into someone’s browser to purge the second.

Versioned URLs help here. WordPress usually appends a version number to theme and plugin assets, so a new release produces a new URL and a stale cached copy never gets served. Files without that pattern, such as uploaded images replaced under the same name, are the ones that need a purge.

Finally, Cloudflare may not be the only CDN in play. A dedicated pull-style CDN, such as the vendor shown below, serves only the asset hostname you point at it. If your caching plugin already rewrites asset URLs to such a hostname, those files never touch Cloudflare’s cache, so running both should be a deliberate choice.

bunny.net
The bunny.net homepage, a pull-style CDN and edge platform, shown as an example of a CDN that serves static assets from a separate hostname
A pull CDN like this serves the asset hostname you point at it, whereas Cloudflare sits in front of the whole domain.

Caching HTML safely with Cache Rules

Caching HTML is where the real speed-up lives, because it removes PHP and database work for anonymous visitors, and it is also where the worst mistakes happen. A page that varies by who is looking at it must never be stored and handed to someone else. The way to stay safe is to define what is private first, and to treat everything else as cacheable only after you have proven it.

Cache Rules are the current mechanism for this in Cloudflare; the older Page Rules still appear in many tutorials, but check the current documentation before building on them. A cache rule has a condition and a result. The result is either Bypass cache or Eligible for cache, and for eligible requests you choose an edge TTL, a browser TTL and cache key options. Per Cloudflare’s documentation, keying the cache on cookies or headers is limited to higher plans, which is why a smaller plan depends on bypass rules instead. Plans also cap the number of rules, so write compact ones.

A bypass rule for the private parts of WordPress covers the admin area, the login page, REST requests, previews and the cookies that mean a person is signed in:

(http.request.uri.path contains "/wp-admin")
or (http.request.uri.path eq "/wp-login.php")
or (http.request.uri.path contains "/wp-json")
or (http.request.uri.query contains "preview=true")
or (http.cookie contains "wordpress_logged_in")
or (http.cookie contains "wp-postpass")
or (http.cookie contains "comment_author")

Set the result to Bypass cache. Then write the rule that makes public HTML eligible. Do not rely on rule order to protect you; Cloudflare’s documentation lets you position rules, but the safest version repeats the exclusions inside the eligible rule so that a private request can never match it:

(http.host eq "example.com")
and (http.request.method eq "GET")
and not (http.request.uri.path contains "/wp-admin")
and not (http.request.uri.path eq "/wp-login.php")
and not (http.request.uri.path contains "/wp-json")
and not (http.request.uri.query contains "preview=true")
and not (http.cookie contains "wordpress_logged_in")
and not (http.cookie contains "wp-postpass")
and not (http.cookie contains "comment_author")

Now the settings on that rule. WordPress core does not send long-lived caching headers for public pages, so edge TTL is usually set explicitly rather than inherited from the origin. Choose a value you are comfortable with if a purge fails, and keep it modest on busy news-style sites. Set browser TTL to respect the origin or keep it short, because stale copies in browsers cannot be purged. Test before trusting it: request a public page twice and look for MISS followed by HIT, then request it with a fake logged-in cookie and confirm you never get a HIT.

$ curl -s -o /dev/null -D - --proto-default https example.com/ | grep -i -E 'cf-cache-status|^age:|cache-control'
$ curl -s -o /dev/null -D - --proto-default https -H 'Cookie: wordpress_logged_in_test=1' example.com/ | grep -i cf-cache-status

The second command should report anything but HIT, typically BYPASS or DYNAMIC.

Should this request be cached at the edge

What kind of request is it?
Admin, login, REST or preview URLsBypass. These pages are private or change on every request.
It carries a logged-in, post-password or commenter cookieBypass. The HTML contains one person’s name, menus or drafts.
Cart, checkout, account pages, or a shopping cookie is presentBypass. Personal and transactional pages are never shared.
An anonymous GET for a public pageEligible for cache, with an explicit edge TTL and a purge on publish.
Walk every request through the same four questions, and cache only what falls through to the last one.

WooCommerce, memberships and the cookies that must bypass the cache

A WooCommerce store is the stress test for every caching rule. Home, category and product pages are mostly the same for everyone, so they are good candidates; the cart, checkout and account pages differ for every shopper. Pages in between, showing a mini cart or a logged-in price, are where mistakes hide.

WooCommerce protects its own sensitive pages by sending no-cache headers and setting cookies when a shopper does something personal. That built-in protection only works if you leave it alone. If a Cache Rule says to ignore the origin’s Cache-Control and use a fixed TTL, it can override those no-cache headers, and the cart page becomes cacheable. This is the single most common way a store ends up showing one shopper’s details to another. Keep the sensitive paths in a bypass rule so the protection no longer depends on the header.

Extend the bypass rule from the previous section with the commerce paths and cookies. The paths are the cart, checkout and my-account pages (use the slugs your store actually uses), plus the cart-fragment and AJAX query strings that WooCommerce uses, commonly wc-ajax and add-to-cart. The cookies are the ones WooCommerce sets for cart contents and sessions: woocommerce_items_in_cart, woocommerce_cart_hash and cookies beginning with wp_woocommerce_session_. Confirm the names on your own site, in the browser’s storage view after adding a product to the cart, since plugins add their own. Membership, course and subscription plugins do the same, and each needs the same treatment for its cookie.

Payment gateways and webhooks deserve a special mention. Stripe, PayPal and shipping services call endpoints on your site from their own servers, and those requests have no cookies and no browser. If a bot rule or a challenge page intercepts them, orders get stuck in pending status with no visible error. Keep REST and callback paths out of challenge rules, and test an actual payment end to end after any security change.

There are quieter problems too. WordPress nonces, the tokens many forms use to verify a request, last a day by default but are valid in two overlapping windows, so a page cached for many hours may contain a token that is about to expire. Visitors then get an expired-link error on submitting a form. Keep edge TTL modest for pages with forms, or use form settings that fetch the token dynamically. And personalisation by cookie, such as a language or currency switcher, is invisible to a cache keyed only on the URL, so one visitor’s choice can be served to everyone. Put the choice in the URL, bypass on that cookie, or use a plan that supports cookie-aware cache keys.

Automatic Platform Optimization: what it is and when to use it

APO is Cloudflare’s WordPress-specific caching product. Instead of you writing the rules from the previous sections, it uses the official Cloudflare plugin, which knows WordPress, to decide what can be cached and when to purge. According to Cloudflare’s overview, it uses Cloudflare Workers to serve dynamic WordPress content from the edge. The appeal is less to configure and a purge integration written by the vendor.

The documentation lists what you need. The Cloudflare plugin must be installed and connected, and Cloudflare notes that the plugin does not support multisite installations. A Free-plan zone has to purchase APO before installing the plugin, while zones on higher plans skip that step, so check your plan’s current terms rather than assuming. Cloudflare also recommends turning off other caching plugins, such as WP Rocket or W3 Total Cache, during the initial setup, and re-introducing them only once you understand which layer does what. The setup itself is short: install the plugin, create an API token from Cloudflare’s WordPress token template, enter your account email and the token in the plugin, apply the recommended settings, then switch APO on.

Verify it with headers, not with the toggle. Cloudflare documents three signs that APO is serving a page: a cache status of HIT, an apo-via header with the value tcache, and an edge-cache header naming the WordPress platform. Send the request with an accept header for text/html, because the response can differ without it. The documentation itself notes that its sample output varies slightly from the stated values, so compare against the current page and look for the pattern rather than character-perfect text. Then publish a change and confirm the page updates, which proves the purge integration works.

$ curl -s -o /dev/null -D - --proto-default https -H 'accept: text/html' example.com/ | grep -i -E 'cf-cache-status|cf-apo-via|cf-edge-cache'

When does APO fit? It suits a content site, blog or brochure site on a standard WordPress setup where most visitors are anonymous, the audience is spread across regions, and you would rather rely on a vendor-maintained integration than your own rules. It is a weaker fit when the site depends on unusual cookies, heavy personalisation, a multisite network, or a plugin stack whose pages vary in ways the integration cannot see. Cloudflare’s APO reference pages cover query parameters, device-type caching and Page Rules; read them before layering your own rules on top.

Weigh the trade honestly. APO may add a recurring cost, makes HTML caching depend on a plugin and token, and gives you less visibility than a rule you wrote. Hand-built Cache Rules are fully inspectable but put the burden of finding every private cookie on you. Unexamined hybrids of both are the real danger.

cloudflare.com
Cloudflare's Automatic Platform Optimization page with a headline about making WordPress sites load faster and three benefit columns
APO packages WordPress-aware HTML caching behind the official Cloudflare plugin; confirm current plan terms on the vendor page.

Speed toggles that need caution: Rocket Loader, Always Online and friends

Most of Cloudflare’s speed switches are harmless. The dangerous ones rewrite your page or promise to rescue it.

Rocket Loader defers the loading of all JavaScript until after the page has rendered. That can help paint speed, but WordPress themes and plugins often depend on scripts running in a particular order, and sliders, menus, form widgets and page builders are the usual casualties. Cloudflare’s guidance is direct: if you see JavaScript or jQuery problems, turn it off and retest. If your site sends a Content Security Policy header, that policy has to be updated to allow it. Individual scripts can be excluded with the data-cfasync attribute set to false, described in Cloudflare’s documentation. Test it on a staging copy and enable it only when a measured gain justifies the debugging.

Always Online is easy to misunderstand. When your origin cannot be reached, Cloudflare serves a stored copy if it has one, and otherwise tries a copy from the Internet Archive, with a banner telling visitors they are looking at an archived page. Three limits follow from the documentation. It only triggers when Cloudflare fails to connect to the origin, not when the origin answers with a 5xx error, so a PHP fatal error or a database connection error, the common WordPress outages, do not activate it. It serves static content only, so carts and comment forms still show the error page. And to build those copies, Cloudflare shares your hostname and popular URL paths with the archive’s crawler, which you may not want for a site that is not meant to be indexed. Treat it as a bonus for hardware outages, never as an uptime plan.

A few other switches overlap with plugins you probably already run. Image optimisation features duplicate an image plugin, and processing images twice wastes effort and can complicate quality settings. Older tutorials recommend Cloudflare’s minification options; the setting has been retired from some dashboards, so verify whether it exists for you and prefer one place for minifying, usually your caching plugin, to avoid double-processing and broken scripts. Email address obfuscation rewrites addresses in your HTML and can break mailto links. Hotlink protection can break embeds and feed readers. Each of these changes the page you serve.

Enable one setting at a time and load the pages that matter after each. A bulk “apply all recommended settings” click followed by a week of vague bug reports is the expensive way to learn the same lessons.

How likely each toggle is to disturb a WordPress site

How to read this: each row is one option, and its dot shows where it sits between Rarely disturbs the site and Often disturbs the site. Placement is an editorial judgement, not a measurement.

  1. 1Compression and HTTP/3Transport-level and invisible to WordPress.
  2. 2Email address obfuscationRewrites mailto links and addresses in HTML.
  3. 3Always OnlineRarely harmful, but gives false comfort for 5xx errors.
  4. 4Image or minify overlap with pluginsDouble processing when two tools both optimise.
  5. 5Rocket LoaderChanges script execution order and timing.
  6. 6HTML caching without bypass rulesCan serve one visitor’s page to another.
Editorial placements based on common failure patterns, not measurements; test each on staging first.

Firewall rules, rate limiting and bot handling for WordPress

Cloudflare’s security features run before your server sees the request, so they are cheap protection for the endpoints WordPress attracts most: the login page, XML-RPC and anything that triggers expensive PHP. They do not replace updates, strong passwords or a security plugin; they reduce the junk that reaches those layers.

Start with managed rules. Cloudflare’s documentation says a free managed ruleset for widely exploited vulnerabilities is available on all plans, while its larger managed ruleset and the OWASP core ruleset are offered on paid plans, so confirm what your plan includes in the WAF section. Leave managed rules on, watch the security events log for a week, and look for false positives before adding anything custom. Custom rules are evaluated in order, plans cap how many you may write, and a terminating action such as Block stops evaluation, so put specific allows and skips ahead of broad blocks. Available actions include Block, Managed Challenge and Skip.

Two practical WordPress rules illustrate the approach. If nothing on your site uses XML-RPC (Jetpack and some mobile apps do, so verify first), block it, since it is a frequent target for password guessing. And challenge the login page:

(http.request.uri.path eq "/xmlrpc.php")
(http.request.uri.path eq "/wp-login.php")

Create these as two separate rules: the first with a Block action, the second with Managed Challenge. After enabling the login rule, sign in from a clean browser profile and with a password manager, because challenges and automated login flows do not always mix. Never apply a challenge to the REST API or payment callbacks without testing a real checkout.

Rate limiting counts requests per client over a short window and takes an action when a threshold is crossed. Cloudflare’s documentation shows that Free plans get very few rate limiting rules with short windows and counting by IP only, so use the allowance on the endpoint that matters most, normally the login path, and verify current limits on the plan page. Real visitor IPs matter here: offices and mobile networks put many people behind one address, so keep thresholds generous enough not to lock out a whole company.

Bot handling needs the most care. Bot Fight Mode is a free feature that challenges traffic matching known bot patterns. Cloudflare’s documentation warns that WAF custom rules and Page Rules cannot skip it, and that it may challenge API or mobile-app traffic. On a WordPress site that means uptime monitors, payment webhooks, caching-plugin preload crawlers, headless front ends and app integrations can be caught. If you rely on any of them, test after enabling it, or use the finer bot products where your plan allows skip rules. Finally, keep Under Attack mode for real incidents: it puts an interstitial check in front of every visitor, and leaving it on after the attack ends costs you conversions and some legitimate crawlers.

A purge strategy that works with your caching plugin

Once HTML is cached at the edge, every content change has to travel through several caches, and the order matters. Your page may be stored by a caching plugin or host cache on the origin, by Cloudflare’s edge, and by the visitor’s browser. If Cloudflare is purged first, it simply fetches the stale copy from the origin cache and stores it again. The rule is to empty layers from the inside out: the origin first, then the edge.

The cleanest way to get that order is to let one integration own the purge. Many caching plugins can talk to Cloudflare and purge it right after clearing their own cache, and the official Cloudflare plugin or APO performs the same job for its own path. Choose one owner. Two plugins issuing independent purges waste your API allowance, create races between layers and make a stale page very hard to debug. Whatever you pick, give the integration an API token with the narrowest permissions it supports, not a global key.

Be precise about what gets purged. After a post is updated, the useful set is the post’s URL, the home page, the archives that list it (category, tag, author, date), and the feeds. Purging by URL is the precise tool, and Cloudflare’s documentation shows that all plans support URL, hostname, tag, prefix and purge-everything operations, though the rate limits differ by plan and are far tighter for the non-URL types on Free. Purge everything is fine on a small site after a theme change and a bad idea on a busy one, because every region then misses at once and the requests land on the origin together.

Cloudflare also does not keep a single global copy. Each data center stores its own, so the first visitor in a region after a purge pays the origin round trip. You cannot pre-warm every location, and a plugin’s preload crawler only warms the origin cache. Tiered caching, where your plan offers it, reduces how many locations go back to the origin.

Finally, verify rather than trust. A success response from the purge call means Cloudflare received the request, not that every copy is gone. Request the page afterwards: you should see a MISS, then a HIT on the next request, and the content should be current. For short periods of theme or CSS editing, Cloudflare’s Development Mode bypasses the edge cache temporarily, which is safer than repeatedly purging.

The caches between a visitor and your database

Visitor’s browser cacheCannot be purged remotely; control it with a short browser TTL.
Cloudflare edge cachePurged by URL, tag, prefix, hostname or everything.
Origin page cacheA caching plugin or host cache; purge this first.
Object cacheRedis or Memcached stores query results; usually flushed on demand.
PHP and databaseThe source of truth that every miss ultimately reaches.
Purge from the bottom of this stack upward, so an outer cache never refills itself from a stale inner one.

Test, monitor and keep a rollback open

Write down a baseline before you start: the current DNS records, a few key URLs with their response times from a tool you trust, and the origin CPU graph. Without one you cannot tell whether Cloudflare helped or only moved the problem. Cache Rules can be saved as drafts and versioned, so stage risky rule changes instead of editing live ones.

Test in a fixed order, so a failure points to its layer. Check DNS and mail first: nameservers, MX, a real test email. Then HTTPS: a clean load with no redirect loop, no mixed-content warnings and a valid padlock. Then public pages: request twice and read the cache status. Then the private paths: sign in, open the admin, add a product to the cart, check out, submit a form, use the login from a private window. Finally the machine-to-machine calls, such as payment webhooks and any API integrations, and a purge after editing a post.

Keep watching for a while. Cloudflare’s analytics show how much traffic the cache answered, and the security events log shows what the WAF and bot features blocked or challenged. Look for false positives: legitimate users, monitors and webhooks in the blocked list. Compare your origin’s access logs and CPU graph before and after, and keep an uptime monitor on the public hostname. A cache hit ratio that stays low on public pages usually means a Set-Cookie header, a query-string pattern or a missing eligible rule, not a Cloudflare fault.

Plan the exit before you need it. In order of increasing severity: bypass or purge the cache; set the affected records to DNS only so traffic goes straight to the origin, which only works smoothly if the origin certificate is publicly trusted; pause Cloudflare for the zone if the dashboard offers that option; or move the nameservers back to the previous provider, using the record export you made at the start. If DNSSEC was re-enabled in Cloudflare, remove the DS record before leaving, mirroring the entry procedure. Keep the old DNS zone intact for a few weeks, and do not cancel anything until the site has survived a publishing, checkout and traffic-spike cycle.

Common symptoms and where to look first

Likely causeFirst check
Too many redirectsFlexible mode plus an HTTPS redirect on the originSSL/TLS mode and origin redirects
Error 526Full (strict) with an invalid origin certificateOrigin certificate validity
Error 521 or 522Origin firewall blocking CloudflareAllow list of Cloudflare ranges
Another user’s contentHTML cached without cookie bypassBypass rules and cf-cache-status
Old content after editsPurge not firing, or long browser TTLPurge integration and TTL settings
Mail stoppedMissing or proxied MX and TXT recordsDNS records for mail
Orders stuck pendingWebhook challenged or blockedSecurity events log
Most Cloudflare problems fall into a handful of patterns, each with a quick first check.

Checklist

  • Record every existing DNS record, including MX, SPF, DKIM, DMARC and verification entries, before touching Cloudflare.
  • Confirm who controls the registrar and whether DNSSEC is enabled, and plan to turn it off before the change.
  • Ask your host whether it already runs a CDN or Cloudflare integration in front of the site.
  • Compare Cloudflare’s imported records line by line with your own list.
  • Set web records to DNS only for the first pass, then verify the nameservers with dig.
  • Keep mail, SSH and FTP hostnames DNS only permanently.
  • Install a publicly trusted certificate on the origin and set SSL/TLS to Full (strict).
  • Load the site and confirm there is no redirect loop and no mixed-content warning.
  • Restore real visitor IPs in the web server or security plugin, and restrict the origin to Cloudflare traffic.
  • Create a bypass rule covering admin, login, REST, previews and logged-in cookies.
  • On a store or membership site, add commerce paths and cookies to the bypass rule.
  • Make public HTML eligible with a self-contained rule and an explicit edge TTL.
  • Confirm MISS then HIT on a public page, and never HIT with a fake logged-in cookie.
  • Choose one owner for purging and confirm a published change reaches the edge.
  • Test a full checkout and payment webhook after every caching or security change.
  • Record a baseline and keep the old DNS export and zone for a few weeks as a rollback.

About this guide. This is general guidance written by WPresident Editorial from documentation and widely used practice. WPresident has not benchmarked the products or methods described. Interfaces and plan limits change, so check the vendor’s current documentation before you act. Not legal, tax or financial advice. See our editorial policy.

Frequently asked questions

Is Cloudflare free for WordPress?

Cloudflare offers a free plan that includes DNS, the proxy, CDN caching for static files, basic firewall protection, bot features and edge certificates, while paid plans add features and higher limits. Add-ons such as APO may carry separate terms. Check the current plan comparison for the features you intend to rely on.

Will Cloudflare make my WordPress site faster?

It often helps visitors far from your server and speeds up static files, because assets come from nearby data centers. It does little for uncached pages, which still wait for PHP and the database. Judge it honestly by comparing response times and server CPU before and after, on both cached and uncached URLs.

How long does a nameserver change take?

Cloudflare's documentation says to allow up to 24 hours, though many changes finish sooner. The delay comes from resolvers caching the old delegation. During the wait some visitors reach the old DNS and some reach Cloudflare, so both must hold identical records. If DNSSEC is on, switch it off at the registrar first.

Why do I get ERR_TOO_MANY_REDIRECTS after enabling Cloudflare?

Usually the SSL/TLS mode is Flexible while your server or a plugin redirects HTTP to HTTPS, so Cloudflare keeps asking over HTTP and the origin keeps redirecting. Install a valid certificate on the origin and switch to Full (strict). Also check the WordPress address settings and any plugin that forces HTTPS.

Does Cloudflare cache my WordPress pages by default?

No. It caches static files by extension, but HTML is not cached unless you create a Cache Rule or use APO. Anything you make cacheable needs bypass conditions for admin, login, logged-in cookies and cart or checkout pages, otherwise one visitor's page can be served to another.

Should I use APO or Cache Rules?

APO suits standard content sites that want WordPress-aware HTML caching and purging maintained by the vendor. Hand-written Cache Rules suit people who want full control and will hunt down every private cookie. Check plan terms and plugin limits, such as no multisite support, and avoid running both without understanding how they interact.

Can I use Cloudflare with WooCommerce?

Yes, but never cache the cart, checkout or account pages, and bypass cache for cookies such as woocommerce_items_in_cart, woocommerce_cart_hash and the session cookies. Keep REST, webhook and payment callback URLs out of challenge rules, and place a test order after every change to caching or security.

Is Always Online a backup for my site?

No. It serves limited static copies only when Cloudflare cannot connect to your origin, and it does not trigger when the origin returns a 5xx error, which covers most WordPress failures. Carts and forms do not work. Rely on real backups, uptime monitoring and a hosting plan with adequate resources.

How do I undo Cloudflare if something breaks?

Work from least to most drastic: purge or bypass the cache, set affected records to DNS only, pause Cloudflare for the zone if available, or restore the old nameservers from your DNS export. A publicly trusted origin certificate makes the DNS-only step safe. Keep the old zone intact for a few weeks.

Does Cloudflare protect me from hacks?

It filters some attacks before they reach your server, but it does not patch a vulnerable plugin, fix weak passwords or clean an infected site. Keep updates, backups and server or plugin security in place, and lock the origin to Cloudflare so attackers cannot bypass the proxy by hitting the server IP directly.

W
Written byWPresident EditorialThe WPresident editorial team. Every article says whether it comes from hands-on use or from documentation, and anything paid for is labelled.

Keep reading

Performance

How to Fix High CPU Usage on WordPress

A practical diagnostic guide to WordPress CPU spikes: read host graphs and logs, tell traffic from code, then fix caching, bots, cron, Heartbeat and plugins.

Read more
WPresident Editorial

Get the Monthly Launch Report

One email a month: the best of last month's articles, new reviews and what changed in WordPress, without the noise.

No spam. Unsubscribe in one click.

Signed and sealed,
The WPresident
↑↓ move↵ openEsc closeAll results