Skip to main content
Website & Hosting

How to Set Up Cloudflare R2 for WordPress Media Storage in 2026

Alex MorganAlex MorganSeptember 25, 20265 min read

Disclosure: Some links in this article are affiliate links. If you click and make a purchase, we may earn a commission at no extra cost to you. This does not influence our editorial recommendations - we only recommend products and services we genuinely believe in. Read our full affiliate disclosure.

How to Set Up Cloudflare R2 for WordPress Media Storage in 2026 – featured image

Storing WordPress media uploads (images, PDFs, audio files, and videos) directly on your web server's local filesystem creates serious scalability problems: disk space fills rapidly, server migrations require multi-gigabyte rsync transfers, and every image request consuming server bandwidth adds to monthly hosting bills.

Cloudflare R2 solves these problems completely. With $0 egress fees, native Cloudflare CDN edge delivery, and a fully S3-compatible API, R2 is the ideal media offloading destination for WordPress in 2026.

This guide walks through the entire setup process from creating an R2 bucket and generating API credentials to connecting WordPress with WP Offload Media and publishing assets through a custom branded subdomain.


Architecture Overview


Step 1: Create a Cloudflare R2 Bucket

  1. Log into dash.cloudflare.com and navigate to R2 Object Storage in the left sidebar.
  2. Click Create bucket.
  3. Enter a descriptive bucket name such as example-com-media. Bucket names are globally unique.
  4. Select a Bucket location - choose Automatic (Global) for worldwide edge proximity, or a specific region (ENAM, EEUR, APAC) for compliance requirements.
  5. Click Create bucket.

Step 2: Generate R2 API Credentials (Access Keys)

  1. In the R2 dashboard sidebar, click Manage R2 API tokens.
  2. Click Create API token.
  3. Set Token name: wordpress-media-token.
  4. Set Permissions: Select Object Read & Write (do NOT grant Admin read/write unless required).
  5. Under Specify bucket, select the specific bucket created in Step 1.
  6. Click Create API Token.
  7. Copy and securely save the displayed Access Key ID and Secret Access Key. The secret key is only shown once.

Also note your Account ID (visible on the R2 overview page - top right corner).

Your R2 S3-compatible endpoint URL follows this format:


Step 3: Configure a Custom Public Domain for R2

By default, R2 buckets are accessible via a temporary *.r2.dev URL. For production, use a branded subdomain.

  1. In your R2 bucket dashboard, click Settings > Custom Domains.
  2. Click Connect Domain.
  3. Enter your subdomain, for example: media.example.com.
  4. Cloudflare automatically adds a CNAME DNS record pointing to R2 if your domain is managed by Cloudflare DNS.
  5. Click Connect and wait ~30 seconds for propagation.

Your media files will now be publicly accessible at:


Step 4: Install and Configure WP Offload Media

WP Offload Media (Delicious Brains) is the most battle-tested WordPress media offloading plugin, with native support for any S3-compatible endpoint including Cloudflare R2.

Install the Plugin

  1. Go to WP Admin > Plugins > Add New.
  2. Search for "WP Offload Media Lite" (free version supports S3-compatible providers).
  3. Click Install Now then Activate.

Configure the S3 Connection

  1. Navigate to Settings > Offload Media.
  2. Click Define access keys in wp-config.php (recommended for security) and add the following constants to your wp-config.php file:
  1. Back in the plugin settings, select Amazon S3 as the provider.
  2. Enter your bucket name: example-com-media.
  3. Under Custom Endpoint, enter: `` https://.r2.cloudflarestorage.com ``
  4. Set Region: auto.

Configure the Public URL

  1. Under Delivery Settings, enable Custom Domain.
  2. Enter your custom domain URL: https://media.example.com.
  3. Enable Force HTTPS.

Enable Key Upload Settings

  • ✅ Remove Files From Server – Deletes local copies of uploaded files after successful R2 upload to save server disk space.
  • ✅ Copy New Files to R2 – Automatically uploads any new media files.
  • ✅ Rewrite URLs – Replaces all wp-content/uploads/ URLs with R2 CDN URLs in your database and HTML output.

Step 5: Migrate Existing Uploads to R2

For existing sites with thousands of local media files, WP Offload Media provides a migration wizard:

  1. Go to Settings > Offload Media > Offload Existing Media.
  2. Click Start Migration.
  3. The plugin processes uploads in background batches - you can safely close the browser and return later.

For large bulk migrations (50,000+ files), using WP-CLI is faster:


Step 6: Verify Delivery and Cache Performance

After migration, verify assets are being served from your R2 custom domain:

  1. Open any WordPress post or page.
  2. Right-click any image and click Inspect.
  3. In the browser Network tab, confirm the image src URL reads https://media.example.com/wp-content/uploads/....
  4. Check response headers for cf-cache-status: HIT - confirming Cloudflare's edge CDN is caching the assets globally.

Optional: Enable Cloudflare Cache Rules for R2

For maximum cache performance, create a Cache Rule in the Cloudflare dashboard:

  • URL pattern: media.example.com/*
  • Cache Level: Cache Everything
  • Edge Cache TTL: 1 month

This ensures all media files are cached at Cloudflare's 330+ global edge nodes, reducing R2 API read operations (Class B) to near-zero for popular assets.


Bandwidth Savings Calculation

For a WordPress blog serving 5TB of media bandwidth per month, the savings are dramatic:

Hosting MethodMonthly Media Bandwidth Cost
Stored on VPS (1GB RAM Droplet)Server overload + extra $20–$80/mo in server upgrades
AWS S3 + CloudFront~$450/month ($0.09 egress × 5,000 GB)
Cloudflare R2 + Edge~$7.50/month (storage only, $0 egress)

The setup described in this guide transforms an $8/month Hetzner VPS into a media powerhouse capable of serving global audiences without ever touching your server's bandwidth cap.

#Cloudflare R2#WordPress#Object Storage#Media Offloading#Web Performance

Frequently Asked Questions

Yes. Cloudflare R2 exposes a fully S3-compatible API endpoint. Plugins like WP Offload Media (Delicious Brains), Media Cloud, or Offload Media Lite can connect to R2 by specifying a custom S3 endpoint URL, your R2 Account ID, an Access Key ID, and Secret Access Key. No code modifications are needed.

Absolutely. In the Cloudflare dashboard under your R2 bucket settings, you can link any domain or subdomain (e.g., media.example.com) managed by Cloudflare DNS. The custom domain is instantly proxied through Cloudflare's global CDN network, providing free SSL, HTTP/3, and edge caching with zero extra cost.

Not if you use WP Offload Media. The plugin rewrites all existing attachment URLs in WordPress's database to point to R2, and can optionally remove local copies once confirmed to be stored on R2. A search-and-replace step using WP-CLI ensures no embedded image URLs in post content are broken.

Yes. Cloudflare R2 includes a permanent free tier of 10GB of storage, 1,000,000 Class A (write) operations, and 10,000,000 Class B (read) operations per month. Most new or small WordPress sites will fit within the free tier for several months before requiring paid storage at $0.015/GB.

Alex Morgan - Founder & Lead Editor
Alex Morgan·Founder & Lead Editor

Alex Morgan is the founder and lead editor of RemoGrid. With over six years of hands-on experience in remote operations, cross-border freelance workflows, and AI tool benchmarking, Alex independently tests and audits software platforms to help modern digital workers build sustainable online income streams. He regularly reviews international payment systems (Wise, Stripe, Payoneer, local mobile wallets) and conducts real-world usability benchmarks across AI productivity tools.

Related Articles

Featured image for Best Cheap Dedicated Servers for Game Server Hosting in 2026Website & Hosting

Best Cheap Dedicated Servers for Game Server Hosting in 2026

Discover the best budget-friendly bare-metal dedicated servers for hosting Minecraft, Rust, Palworld, and ARK in 2026, comparing CPU single-core performance, anti-DDoS mitigation, and bandwidth.

#Dedicated Servers#Game Hosting
September 25, 20267 min read
Featured image for Best Object Storage for Media-Heavy Websites in 2026Website & Hosting

Best Object Storage for Media-Heavy Websites in 2026

Compare the best cloud object storage solutions for media-heavy websites in 2026. Detailed cost breakdown of Cloudflare R2, Backblaze B2, Wasabi, AWS S3, and DigitalOcean Spaces.

#Object Storage#Cloud Storage
September 25, 20266 min read
Featured image for Best WordPress Security Audit Tools & Plugins in 2026Website & Hosting

Best WordPress Security Audit Tools & Plugins in 2026

Compare the top WordPress security audit tools and plugins in 2026, including Wordfence, Solid Security, Patchstack, Sucuri, and WPScan CLI, with actionable hardening steps for every site.

#WordPress Security#Security Plugins
September 25, 20266 min read