Pricing Get plugin

How to find and fix broken images in WordPress

Quick answer: open the broken image's address in a new tab and read the status. 404 means the file is not at that URL (deleted, wrong domain after a move, or a capital letter that no longer matches). 403 means permissions or hotlink protection. A 200 that is not an image means a CDN or host is returning an HTML page instead. To find all of them at once, list every image URL WordPress knows about and check each one, as shown below. Also check the Media Library itself: a file can be missing on disk while nothing in your content points to it by URL.

1. Diagnose one broken image

  1. Right-click the broken image and choose Copy image address (or open your browser's developer tools, Network tab, filter Img, reload, and read the Status column).
  2. Paste the address into a new tab, or check it from a terminal:
curl -s -o /dev/null -w '%{http_code}  %{content_type}\n' https://example.com/wp-content/uploads/2026/10/photo.jpg
ResultUsual causeFix
404File deleted, never copied to the new server, URL still points at an old domain, or the case of the file name changedSections 3, 5 and 6
403 on your own imageFile or folder permissions, a security plugin or .htaccess rule, or hotlink protection on your CDNWordPress recommends 644 for files and 755 for folders; check hotlink rules allow your own domain
200 but text/htmlThe host or CDN answers missing files with an HTML page, or a bot challengeTreat it like a 404 and look for the file
000 / timeoutDomain no longer exists (common for old CDN or staging hostnames), or the server is downPoint the image at your own domain; see section 5
200 image in a new tab, broken on the pageMixed content (an http:// image on an https:// page), or a lazy-loading or optimisation plugin rewriting the URLSwitch the URL to https://; disable lazy-load or optimisation to test

2. Find every broken image in your content

The quick way to list image URLs is a regular expression over post content, but it misses srcset, single-quoted attributes and featured images. This script uses WordPress's own HTML parser (WP_HTML_Tag_Processor, WordPress 6.2 and later) and prints one row per image: post ID, where it was found, and the URL. Save it as list-images.php in your WordPress folder:

<?php
// wp eval-file list-images.php > images.tsv
// Prints: post ID, where, image URL. Covers content (img and picture/source src + srcset),
// featured images and custom fields whose value is an image URL.
$home = untrailingslashit( home_url() );
$abs  = function ( $u ) use ( $home ) {
	$u = trim( html_entity_decode( $u ) );
	if ( 0 === strpos( $u, '//' ) ) return 'https:' . $u;
	if ( 0 === strpos( $u, '/' ) ) return $home . $u;
	return $u;
};
$ids = get_posts( array( 'post_type' => 'any', 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => -1 ) );
foreach ( $ids as $id ) {
	$p = new WP_HTML_Tag_Processor( (string) get_post_field( 'post_content', $id ) );
	while ( $p->next_tag() ) {
		if ( ! in_array( $p->get_tag(), array( 'IMG', 'SOURCE' ), true ) ) continue;
		$urls   = array( $p->get_attribute( 'src' ) );
		$srcset = $p->get_attribute( 'srcset' );
		if ( is_string( $srcset ) ) foreach ( explode( ',', $srcset ) as $c ) $urls[] = strtok( trim( $c ), ' ' );
		foreach ( $urls as $u ) if ( is_string( $u ) && preg_match( '#^(https?:)?/#i', trim( $u ) ) ) echo $id, "\tcontent\t", $abs( $u ), "\n";
	}
	$thumb = (int) get_post_meta( $id, '_thumbnail_id', true );
	if ( $thumb ) echo $id, "\tfeatured\t", ( get_post( $thumb ) ? wp_get_attachment_url( $thumb ) : "MISSING ATTACHMENT $thumb" ), "\n";
	foreach ( get_post_meta( $id ) as $key => $values ) {
		if ( '_' === $key[0] ) continue;
		foreach ( $values as $v ) if ( preg_match( '#^https?://\S+\.(jpe?g|png|gif|webp|avif|svg)(\?\S*)?$#i', trim( $v ) ) ) echo $id, "\tmeta:$key\t", trim( $v ), "\n";
	}
}

Then check each unique URL once and keep only the problems. The check records both the status code and the content type, so a 200 that is really an HTML error page is caught too:

wp eval-file list-images.php > images.tsv

cut -f3 images.tsv | grep -v '^MISSING' | sort -u | while read -r url; do
  printf '%s\t%s\n' "$(curl -s -o /dev/null -L --max-time 15 -A 'Mozilla/5.0' -w '%{http_code}\t%{content_type}' "$url")" "$url"
  sleep 0.5
done > img-status.tsv

# Anything that is not "200 + image/*" (000 = no answer or DNS failure)
awk -F'\t' '$1 != "200" || $2 !~ /^image\//' img-status.tsv
grep MISSING images.tsv

To see which posts use a broken URL: grep 'the-url' images.tsv, then wp post list --post__in=ID --fields=ID,post_title,url.

Limits: it reads published content only (drafts are covered by the database search in section 5), it downloads each image once, and it does not see images set in theme CSS, in widgets or in page-builder data. For Elementor, image URLs live in the _elementor_data custom field, which is JSON; wp post meta get ID _elementor_data shows them.

3. Media Library files missing on disk

Every image in the Media Library is a database row plus files in wp-content/uploads: the original and one file per generated size (thumbnail, medium, large…). After a partial restore or a migration that skipped some files, the row survives and the files do not. This script lists both cases without making any web requests:

<?php
// wp eval-file missing-files.php
$ids = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'fields' => 'ids', 'posts_per_page' => -1 ) );
foreach ( $ids as $id ) {
	$file = get_attached_file( $id );
	if ( ! $file || ! file_exists( $file ) ) { echo $id, "\toriginal missing\t", $file, "\n"; continue; }
	$meta = wp_get_attachment_metadata( $id );
	foreach ( (array) ( $meta['sizes'] ?? array() ) as $size => $s ) {
		if ( ! file_exists( path_join( dirname( $file ), $s['file'] ) ) ) echo $id, "\tsize missing: $size\t", path_join( dirname( $file ), $s['file'] ), "\n";
	}
}

A featured image is stored as an attachment ID in the _thumbnail_id custom field. Delete the attachment and the ID stays behind; the theme then shows nothing, or an empty frame. This query lists posts whose featured image no longer exists:

wp db query "SELECT pm.post_id, pm.meta_value AS missing_attachment FROM $(wp db prefix)postmeta pm LEFT JOIN $(wp db prefix)posts a ON a.ID = pm.meta_value WHERE pm.meta_key = '_thumbnail_id' AND a.ID IS NULL"

Set a new one in the editor, or remove the stale reference with wp post meta delete POST_ID _thumbnail_id. ACF image fields also store an attachment ID (whatever their return format), so they go stale the same way.

5. Images broken after a migration or domain change

WordPress stores full image URLs in post content, so after a move every image still points at the old domain (or at http:// after switching to HTTPS). First see where the old address is still used, including drafts and options:

wp db search 'old-domain.example' --stats

Then replace it, dry run first, with a database backup taken. wp search-replace handles serialized data, which a plain SQL REPLACE would break. Skipping the guid column follows the WordPress migration guide's advice not to change GUIDs:

wp search-replace 'https://old-domain.example' 'https://new-domain.example' --skip-columns=guid --report-changed-only --dry-run
# looks right? run it again without --dry-run

Elementor sites need one more step. Elementor saves its layout as JSON with escaped slashes (https:\/\/old-domain.example\/…), so the command above makes no replacements there. On our test site it reported 0 changes for an Elementor image until we searched for the escaped form. Use Elementor's own tool, Replace URL (under Elementor's Tools), or its WP-CLI command, then clear Elementor's generated files (Elementor's guide):

wp elementor replace-urls https://old-domain.example https://new-domain.example

Run wp db search again afterwards. Anything left is usually in a page builder or plugin that stores data in its own format; fix those in that plugin's settings.

6. Upper/lower case mismatches after moving hosts

Windows and (by default) macOS treat Photo.JPG and photo.jpg as the same file. Linux servers do not. Move a site from a Windows or Mac machine (or a backup made on one) to a Linux server and images whose case does not match exactly return 404, although the file is right there. This finds them from the 404 list in section 2:

UPLOADS=$(wp eval 'echo wp_upload_dir()["basedir"];')
awk -F'\t' '$1 == "404" {print $3}' img-status.tsv | grep '/wp-content/uploads/' | while read -r url; do
  rel=$(printf '%s' "$url" | sed 's#.*/wp-content/uploads/##')
  match=$(find "$UPLOADS" -ipath "$UPLOADS/$rel" -print -quit)
  [ -n "$match" ] && printf '%s\t%s\n' "$url" "$match"
done

Each line shows the URL used in your content and the file that actually exists. Either rename the file to match, or change the URL with wp search-replace (dry run first).

7. Images hosted on other sites

Images embedded from another site's URL ("hotlinked") break when that site deletes or moves them, or turns on hotlink protection, which often answers 403. If you have the rights to use the image, upload a copy to your Media Library and point the post at it. Otherwise replace or remove it. Old CDN hostnames that no longer resolve (status 000) belong in section 5.

Where a link checker helps, and where it does not

The checks above are a one-off audit. A link checker plugin repeats the URL part in the background and tells you when an image breaks later. Broken Link Checker by WPMU DEV, for example, has an HTML images link type in its Local engine settings. LinkTender, our plugin, checks images too (the Images option, on by default):

Broken links rather than images? See how to find broken links in WordPress without a plugin.

FAQ

Why do my images show in the Media Library but not on the page?

The Media Library shows the thumbnail size, while the page may use another size or an old URL in the post content. Check the URL the page actually requests (step 1). A missing size is fixed with wp media regenerate --only-missing; an old domain with wp search-replace.

Is it safe to run wp search-replace on a live site?

Take a database backup first and always run it with --dry-run before the real run. The dry run lists how many replacements each table and column would get, so a typo shows up before anything changes.

Do broken images hurt SEO?

Mostly they hurt visitors: a missing image cannot appear in image search results, and empty frames make a page look neglected. Fix them first on the pages that get traffic.

Can I do this without SSH or WP-CLI?

Partly. A desktop crawler (Screaming Frog's free version crawls up to 500 URLs) reports broken images that appear on rendered pages, and the Better Search Replace plugin does the domain replacement from wp-admin. Missing Media Library files and stale featured-image IDs need database access or a plugin built for that.

Get told when an image breaks later

Re-running these checks by hand gets old. LinkTender is a free WordPress plugin that checks the links and images in your content from your own server: posts, blocks, Elementor, shortcode builders such as Divi and WPBakery, custom fields, comments, menus and widgets. Bot-blocked links are marked Unverified instead of broken, and you can fix a URL everywhere it appears. No account, no link quota, and nothing is checked until you click Start checking links. Get it free on WordPress.org or read the docs.

Last updated: