Skip to content
Home » Articles » Fix Broken Image Links in WordPress Affiliate Sites (2026)

Fix Broken Image Links in WordPress Affiliate Sites (2026)

Intro

Fixing broken image links in WordPress affiliate niche sites in 2026 means checking the full image path, not just the editor view. On affiliate sites, image failures usually hurt twice: product comparison pages lose trust, and image search traffic drops because crawlers see missing assets, redirect loops, or blocked files instead of usable media.

This guide assumes a self hosted WordPress site running on Linux, PHP 8.2 or 8.3, and either Apache or Nginx. The focus is practical triage for affiliate content, where broken image links often come from expired hotlinks, CDN rewrites, offloaded media plugins, failed regeneration, or domain changes after a migration. If your site also depends on image SEO, it helps to review web image performance best practices, WordPress media optimization plugin comparisons, and the Flux Media Optimizer overview.

Prerequisites

You need a working shell and WordPress admin access because broken image links usually require both database checks and filesystem verification.

  • WordPress 6.6 or 6.7
  • PHP 8.2 or PHP 8.3
  • WP-CLI 2.10 or newer
  • MySQL 8.0 or MariaDB 10.6 or newer
  • Ubuntu 24.04 LTS, Debian 12, or similar Linux host
  • SSH access as a non root deployment user, with `sudo` available if needed
  • A recent database backup and `/wp-content/uploads/` backup
  • Optional CDN or image proxy access if you use one
ComponentRecommended VersionWhy It Matters
WordPress6.6 or 6.7Current media handling and attachment metadata
PHP8.2 or 8.3Common production baseline in 2026
WP-CLI2.10+Fast attachment and search-replace checks
MySQL or MariaDB8.0 / 10.6+Reliable content and meta queries

Installation And Setup

This setup stage gives you a repeatable way to verify whether the problem is in the database, the filesystem, or the delivery layer.

First, move into the WordPress document root as your normal deploy user, not root.

cd /var/www/example.com/public
wp core version
wp plugin list --status=active

Expected output is short and should confirm the site is reachable from WP-CLI.

6.7.1
+----------------------+--------+-----------+---------+
| name                 | status | update    | version |
+----------------------+--------+-----------+---------+

Next, identify a broken image URL from the front end, then inspect the matching attachment record.

wp post list --post_type=attachment --fields=ID,post_title,guid --format=table | head -20

If you already know the attachment ID, inspect its metadata.

wp post meta get 123 _wp_attached_file
wp post meta get 123 _wp_attachment_metadata

For affiliate sites that imported images from merchants or external feeds, also search for hardcoded URLs inside post content.

wp db query "SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%old-cdn.example.com%' LIMIT 20;"

If you recently migrated domains, check the active upload base path.

wp option get siteurl
wp option get home
wp eval 'print_r( wp_get_upload_dir() );'

On a healthy site, the `baseurl` should match your current production domain and the `basedir` should point to the live uploads directory.

Configuration

The right configuration depends on where the break happens. For WordPress affiliate niche sites, there are four common paths: local uploads, CDN rewritten URLs, externally hotlinked images, and attachment metadata pointing to files that no longer exist.

Start by validating the uploads path in `wp-config.php` and the web server root. In most cases you should not define a custom uploads constant unless you have a real offload requirement.

<?php
// Usually unnecessary unless you intentionally changed the uploads path.
define('WP_CONTENT_DIR', '/var/www/example.com/public/wp-content');
define('WP_CONTENT_URL', 'https://example.com/wp-content');

If you are using Nginx, confirm uploads are publicly reachable and not blocked by an overzealous location rule.

location /wp-content/uploads/ {
    expires 30d;
    add_header Cache-Control "public, max-age=2592000";
    try_files $uri =404;
}

If you are using Apache, check that image requests are not being rewritten back into `index.php`.

RewriteCond %{REQUEST_URI} ^/wp-content/uploads/
RewriteRule .* - [L]

For CDN based setups, compare one working image and one failing image. Broken links often happen when the database stores `https://cdn.example.com/…` but the CDN no longer has the object, or when a plugin rewrites to a stale host. If your setup uses Flux tools for media work, the Unused Media Cleaner page and AI Media Alt Creator are useful references for attachment centric workflows, but they do not replace path verification.

A quick decision matrix helps:

SymptomLikely CausePrimary Fix
404 on original fileMissing upload fileRestore file or replace attachment
404 on `-scaled` or thumbnail URLMissing generated sizesRegenerate thumbnails
CDN URL fails, local URL worksCDN sync or rewrite issueRe-sync or disable stale rewrite
HTTPS page loads HTTP imagesMixed content after migrationSearch-replace old URLs
Merchant hosted image disappearsExternal hotlink expiredDownload and host locally

Usage And Execution

This execution flow fixes the most common broken image link patterns in a safe order.

Verify The Broken URL At The HTTP Layer

What you need here is a direct response check, because browser previews can hide redirect problems.

curl -I https://example.com/wp-content/uploads/2026/04/product-shot.webp
curl -I https://cdn.example.com/wp-content/uploads/2026/04/product-shot.webp

A good response is usually `200 OK`. A `301` to an unexpected host, `403`, or `404` tells you where to investigate next.

Confirm The Attachment Still Points To A Real File

What matters is whether WordPress metadata and disk contents still agree.

wp post meta get 123 _wp_attached_file
ls -lah wp-content/uploads/2026/04/product-shot.webp

If metadata exists but the file is gone, restore it from backup or replace the media item in the library. On affiliate sites, this often happens after cleanup tools delete files that are still embedded in older buying guides.

Regenerate Missing Intermediate Sizes

What you are fixing here is thumbnail drift, because WordPress can reference `-300×300`, `-768×432`, or `-scaled` variants that no longer exist.

wp media regenerate --yes

Expected output should include regenerated sizes and skipped items where originals are intact.

Found 248 images to regenerate.
Success: Regenerated 248 of 248 images.

If you only want to target a subset after a migration, run:

wp media regenerate 123 124 125 --yes

Repair Old Domains Or CDN Hosts In Content

What you are fixing is hardcoded image markup left behind by migrations, feed imports, or plugin changes.

Run a dry run first.

wp search-replace 'https://oldsite.example' 'https://example.com' --skip-columns=guid --all-tables --dry-run
wp search-replace 'https://old-cdn.example.com' 'https://cdn.example.com' --skip-columns=guid --all-tables --dry-run

If the matches look correct, apply the replacement.

wp search-replace 'https://oldsite.example' 'https://example.com' --skip-columns=guid --all-tables
wp search-replace 'https://old-cdn.example.com' 'https://cdn.example.com' --skip-columns=guid --all-tables

For affiliate content, be careful not to bulk replace merchant image hosts unless you have already mirrored those assets locally.

Re-Import Or Localize External Merchant Images

What you are doing here is removing dependency on unstable third party hotlinks. That matters because many affiliate programs rotate or expire image URLs.

A simple pattern is:

  1. Download the remote image.
  2. Import it into WordPress.
  3. Replace the old hotlink in post content.
wget -O /tmp/merchant-image.webp 'https://merchant-cdn.example.net/images/item-42.webp'
wp media import /tmp/merchant-image.webp --title='Item 42 Product Image'

Then locate the old URL and replace it with the new attachment URL.

wp db query "SELECT ID, post_title FROM wp_posts WHERE post_content LIKE '%merchant-cdn.example.net/images/item-42.webp%' LIMIT 20;"

Verify Front End Rendering And Indexability

What you are checking now is whether the fix is visible to users and crawlable by search engines.

  • Open the repaired page in a private browser window
  • Check the image request in DevTools Network tab
  • Confirm the image URL returns `200`
  • Confirm there is no mixed content warning
  • Confirm the page source references the new or corrected URL
  • Re-submit the affected page in Google Search Console if the page was important revenue content

Troubleshooting

These failure cases are common on WordPress affiliate niche sites and usually explain why the first fix attempt did not stick.

CDN Still Serves Broken Paths After Local Files Are Fixed

This happens when the origin is healthy but the CDN still points to deleted objects or an outdated pull zone. Purge the CDN cache, then test the origin URL directly before re-enabling rewrites. If the site uses a plugin that rewrites uploads to a CDN host, temporarily disable that rewrite and confirm local media loads first.

curl -I https://example.com/wp-content/uploads/2026/04/product-shot.webp
curl -I https://cdn.example.com/wp-content/uploads/2026/04/product-shot.webp

If origin is `200` and CDN is `404`, the problem is outside WordPress.

Attachment Exists But The File Path Is Wrong After Migration

This usually shows up when `basedir` changed, such as moving from `/srv/www/site/current/public` to `/var/www/example.com/public`. WordPress may still hold valid relative metadata, but the actual files were not copied into the new uploads tree. Re-sync `/wp-content/uploads/` from backup, then regenerate sizes.

rsync -avz /backup/uploads/ wp-content/uploads/
wp media regenerate --yes

Mixed Content Breaks Images On HTTPS Pages

This is common after older affiliate sites move to HTTPS and still embed `http://` image URLs in post content or custom fields. Browsers block them, making the images appear broken even if the origin responds.

wp search-replace 'http://example.com/wp-content/uploads/' 'https://example.com/wp-content/uploads/' --skip-columns=guid --all-tables --dry-run

If the dry run looks right, apply it. Also inspect any page builder fields, options tables, and affiliate comparison shortcodes that may store URLs outside standard post content.

Conclusion

Fixing broken image links in WordPress affiliate niche sites is mostly a process of narrowing the fault domain: metadata, files, rewrites, CDN delivery, or old external sources. In 2026, the biggest trap is assuming the Media Library preview proves the image is healthy. It does not. You need to validate the attachment record, the actual upload path, and the live HTTP response.

For affiliate pages, I would prioritize local hosting for revenue critical images, thumbnail regeneration after any migration, and regular checks for stale CDN or merchant URLs. That reduces both ranking loss and conversion loss. If you are also improving image search performance, the next useful reads are best WordPress SEO plugins for agencies, Alt Text Checker, and solutions for agencies.