Hosting & Migration 5 min read

How to set up Cloudflare for a WordPress site

How to set up Cloudflare for WordPress safely: adding the site, DNS import, nameservers, SSL mode, caching rules, APO, security settings and troubleshooting.

Usman Muhammad UsmanUpdated October 13, 2026
How to set up Cloudflare for a WordPress site

Cloudflare sits between your visitors and your web server, providing a CDN, DNS, SSL and security features, many of them free. For WordPress sites, it can improve speed for distant visitors and block malicious traffic. Setting it up takes less than an hour, but a few settings must be right to avoid broken pages or redirect loops. Here is how I do it.

What Cloudflare does

When you use Cloudflare, your domain’s DNS is managed by Cloudflare and traffic for proxied records passes through Cloudflare’s network. Cloudflare caches static files near visitors, filters malicious requests and can provide SSL for the connection between visitors and Cloudflare.

The free plan includes a CDN, DNS, basic DDoS protection, SSL and some security rules. Paid plans add features such as advanced firewall rules, image optimisation and APO for WordPress.

Prepare before switching

Before adding the site, note your current DNS records, especially MX, SPF, DKIM and other TXT records for email. Check whether your host provides its own CDN or has specific Cloudflare instructions. Take a backup of the site.

Lower the TTL on existing records if possible, so changes spread faster. See DNS records explained.

Cloudflare setup
  1. 1Note DNSEspecially email
  2. 2Add siteReview imported records
  3. 3NameserversAt the registrar
  4. 4SSL Full (strict)Not Flexible
  5. 5Caching and securityBypass dynamic pages

Add your site to Cloudflare

Create a Cloudflare account, add your domain and choose a plan. Cloudflare scans your existing DNS records and imports them. Review every imported record carefully against your notes; scans sometimes miss records, especially for subdomains and email.

Add any missing records manually. Make sure email records are present and correct before continuing.

Proxied vs DNS-only records

Each A, AAAA and CNAME record can be proxied, shown by an orange cloud, or DNS-only, a grey cloud. Proxied records route traffic through Cloudflare for caching and security. DNS-only records simply resolve to your server.

Proxy your website records, such as the root domain and www. Keep mail-related records and records for services that do not work through a proxy, such as some FTP or control panel subdomains, as DNS-only.

Change nameservers

Cloudflare gives you two nameservers. At your domain registrar, replace the existing nameservers with Cloudflare’s. Once the change propagates, Cloudflare becomes your DNS provider and starts proxying traffic.

If DNSSEC is enabled at your registrar, disable it before changing nameservers, then re-enable it through Cloudflare afterwards, following Cloudflare’s instructions.

Set the SSL mode

Under SSL/TLS, choose Full (strict) if your server has a valid SSL certificate, which most hosts provide. This encrypts traffic between visitors and Cloudflare and between Cloudflare and your server, and checks the server’s certificate.

Avoid Flexible mode with WordPress, which only encrypts traffic between visitors and Cloudflare and commonly causes redirect loops. Enable Always Use HTTPS and Automatic HTTPS Rewrites. See setting up SSL and HTTPS.

Caching settings

By default, Cloudflare caches static files such as images, CSS and JavaScript, but not HTML pages. Set the browser cache TTL to respect existing headers or a sensible value. Enable Brotli compression, often on by default, and HTTP/3.

Cache rules can cache HTML for anonymous visitors, but must bypass the cache for logged-in users, admin pages, cart, checkout and account pages. Configure these carefully or use APO.

APO for WordPress

Cloudflare’s Automatic Platform Optimization for WordPress caches full HTML pages at the edge and automatically bypasses the cache for logged-in users and WooCommerce dynamic pages. It requires the Cloudflare WordPress plugin to purge cache when content changes.

APO can dramatically improve load times for visitors worldwide. It is included in some paid plans or available as an add-on. Test thoroughly on stores and membership sites.

Security settings

Set the security level to medium and enable Bot Fight Mode on the free plan, testing that legitimate services such as payment webhooks are not blocked. Use WAF custom rules to challenge or block traffic to wp-login.php from countries you do not serve, or rate-limit login attempts.

Cloudflare’s managed rules, available on paid plans, protect against common WordPress attacks. See do you need a WAF.

The Cloudflare WordPress plugin

The official plugin connects WordPress to Cloudflare, applies recommended settings, enables APO and purges the cache automatically when you update content. Some caching plugins, such as WP Rocket, also integrate with Cloudflare.

Use one tool to manage Cloudflare cache purging to avoid conflicts.

Restore visitor IP addresses

Because traffic passes through Cloudflare, your server sees Cloudflare’s IP addresses instead of visitors’. Most hosts and security plugins handle this automatically, but check that security logs and comment tools show real visitor IPs.

If not, configure your server or security plugin to use the CF-Connecting-IP header from Cloudflare’s IP ranges.

Troubleshooting

Redirect loops usually mean SSL mode is Flexible or there are conflicting redirect rules; switch to Full (strict). Stale content after updates means the cache needs purging. Broken admin or checkout pages often mean HTML caching rules are too aggressive.

Pause Cloudflare temporarily from the dashboard to see whether a problem is caused by it. Check the Security Events log for blocked legitimate requests.

Getting help

Cloudflare setup and tuning is part of my speed optimization and hosting and migration services. For deciding whether you need it, read do you need a CDN.

For DDoS concerns, see DDoS protection for small business websites.

Key takeaways

  • Check every imported DNS record, especially email, before switching nameservers.
  • Use Full (strict) SSL mode, never Flexible, with WordPress.
  • Bypass caching for logged-in users, admin, cart and checkout.
  • Pause Cloudflare to diagnose problems quickly.

Frequently asked questions

Is Cloudflare free?

The free plan includes CDN, DNS, SSL and basic security. Paid plans add advanced features.

Will Cloudflare break my email?

Not if MX and other email records are imported correctly and left DNS-only.

Why do I get too many redirects after enabling Cloudflare?

Usually Flexible SSL mode. Switch to Full (strict).

What is Cloudflare APO?

A feature that caches full WordPress pages at the edge, bypassing the cache for dynamic content.

Does Cloudflare improve SEO?

Indirectly, by improving speed and reliability.

Can I use Cloudflare with WooCommerce?

Yes, with rules that bypass caching for cart, checkout and account pages.

Free website audit

Get a free audit of your website

Tell me your URL and I'll send a short, prioritized list of the speed, SEO and security fixes that will make the biggest difference.

  • No obligation, no sales call
  • 5.0 rating on Google and Upwork
  • Reply within one business day
Written by Muhammad UsmanWeb Development Team Lead with 5+ years building WordPress, WooCommerce, Shopify and Wix websites. Experience · Certificates About me

More on Hosting & Migration

All Hosting & Migration articles

Have a project in mind?

Tell me what you're building and I'll reply with next steps and an estimate.