---
title: Cloudflare Integration
description: "Purge Cloudflare cache automatically from WordPress with Powered Cache. Learn how to create an API token, find your Zone ID and store keys in wp-config."
url: "https://poweredcache.com/docs/cloudflare-integration/"
updated: "2026-12-02"
category: CDN
---

# Cloudflare Integration

If your site runs behind Cloudflare, Cloudflare can keep its own copies of your files and pages. The Cloudflare integration clears the Cloudflare cache whenever you clear all of the Powered Cache cache, so visitors do not keep getting outdated content from Cloudflare. It also gives you a button to clear Cloudflare on its own.

**Available in:** Powered Cache (free)
**Where to find it:** Powered Cache → Integrations, in the *CDN and proxy* group
**Requires:** a Cloudflare account with your domain added as a zone.

## What is purged and when

Powered Cache always purges **everything** in the Cloudflare zone. It does not purge single URLs. A purge is sent when:

- you clear all caches with **Purge All Cache**, from the admin bar or from Powered Cache → Tools,
- you click **Purge Cloudflare Cache** in the Powered Cache menu of the admin bar. This clears only Cloudflare.

Publishing or updating a post, **Purge Page Cache** and the automatic clearing of single pages do not purge Cloudflare. After a manual purge, Powered Cache shows *Cloudflare cache flushed, it can take up to 30 seconds to delete all cache from Cloudflare!*

## Connect Cloudflare

1. In Cloudflare, create an [API token](#api-token) and copy it.
2. Copy your [Zone ID](#zone-id).
3. In WordPress, go to **Powered Cache → Integrations** and turn on **Cloudflare** (*Purge Cloudflare cache*). The other Cloudflare fields can be edited once it is on.
4. Paste the token into **Cloudflare API Token** and the Zone ID into **Cloudflare Zone ID**. Leave **Cloudflare Email** and **Cloudflare API Key** empty.
5. Click **Save Settings**.
6. Test the connection: in the admin bar, open the Powered Cache menu and click **Purge Cloudflare Cache**. You should see the success message.

The integration only becomes active when **Cloudflare** is on, a Zone ID is set, and either an API token or an email address with a global API key is available. Until then, the **Purge Cloudflare Cache** item does not appear. If Cloudflare is on without a Zone ID, the settings screen warns: *Cloudflare purge is enabled, but no Cloudflare Zone ID is configured.*

## Credentials

### API token (recommended)

An API token can be limited to exactly what Powered Cache needs, so it is much safer than the global API key. The **Cloudflare API Token** field links to the API tokens page of your Cloudflare profile. Create a custom token with:

- **Permissions:** Zone → Cache Purge → Purge.
- **Zone resources:** include only the zone of this site.

Powered Cache only sends purge requests, so the token does not need any other permission. When a token is set, it is used and the email and global API key are ignored.

### Global API key (legacy)

Older setups use the account email with the global API key. Enter both in **Cloudflare Email** and **Cloudflare API Key**. The global key gives full access to your whole Cloudflare account, so switch to an API token when you can: create the token, enter it, then click **Clear saved value** under the API key and save.

### Cloudflare Zone ID

The ID of the Cloudflare zone (domain) to purge. You find it in the Cloudflare dashboard on the overview page of your domain, in the API section. It is a 32-character code, not your domain name.

### How saved credentials are shown

The token, API key and email are never sent back to the browser after you save them. The API key and token are stored encrypted. Instead of the value, the field shows *Saved value. It is hidden and will remain unchanged unless you replace or clear it.*

- To replace a value, type the new one into the field (*Enter a new value to replace it*) and save.
- To remove it, click **Clear saved value** and save. Click **Keep saved value** to undo that before saving.

These values are also left out when you [export your settings](/docs/import-and-export-settings/#export), so enter them again after importing on another site.

> **Changed in 4.0.1:** Saved credentials now show a clear saved state without returning their contents to the browser. Before, the fields showed a partly masked value.

## Store the key in wp-config.php

To keep the secret out of the database, define it in `wp-config.php`, above the line `/* That's all, stop editing! */`:

```
// API token (recommended).
define( 'POWERED_CACHE_CF_API_TOKEN', 'your-api-token' );

// Or the legacy global API key.
define( 'POWERED_CACHE_CF_API_KEY', 'your-global-api-key' );
```

- A constant takes priority over a value saved in the settings. Leave the matching field empty.
- There are no constants for the email and the Zone ID. Enter the **Cloudflare Zone ID** in the settings, and with `POWERED_CACHE_CF_API_KEY` also the **Cloudflare Email**.
- You still need to turn on **Cloudflare** in the settings.
- The settings screen does not show that a constant is in use. Test it with **Purge Cloudflare Cache**.

See [wp-config Constants](/docs/wp-config-constants/) for all constants.

## Other adjustments while the integration is active

- **Visitor IP addresses:** when a request comes from a Cloudflare IP address, WordPress gets the visitor's real IP from the `CF-Connecting-IP` header instead of Cloudflare's. This matters for comments, security plugins and logs.
- **HTTPS detection:** when Cloudflare reports that the visitor used HTTPS (`X-Forwarded-Proto: https`), WordPress treats the request as HTTPS. This prevents redirect loops and mixed-content problems with Cloudflare's Flexible SSL mode.

## Troubleshooting

### "Could not flush Cloudflare cache"

- Check that the Zone ID belongs to the same domain and the same Cloudflare account as the token.
- Check that the token has the *Cache Purge* permission for that zone and has not expired or been limited to other IP addresses.
- With the global API key, check that the email is the one you log in to Cloudflare with.
- Turn on the [Debug Log](/docs/debug-log/) and purge again. Cloudflare's response, including its error message, is written to the log.

### The Purge Cloudflare Cache item is missing

The integration is not complete yet: check the toggle, the Zone ID and the credentials. The item is shown only to administrators (network administrators when Powered Cache is network-activated).

## Related docs

- [Clear Cache](/docs/clear-cache/)
- [CDN Integration](/docs/cdn-integration/)
- [Hosting Compatibility](/docs/hosting-compatibility/)
- [wp-config Constants](/docs/wp-config-constants/)
