Auto-fix missing alt text site-wide (page builders & carousels)
A tiny mu-plugin that adds descriptive alt to any image missing it, including Elementor/Divi and logo carousels that Bing & Google flag.
When Bing Webmaster or Google flags images as 'Alt attribute missing' even after you've applied alt text, the culprit is almost always a page-builder widget (Elementor/Divi, Essential Addons logo carousels, sliders) that renders the <img> with a hardcoded empty alt and ignores the Media Library. This drop-in fixes every such image at the source.
It backfills alt text server-side from each image's filename, so search crawlers see real descriptive alt on every image. It only touches images that are MISSING alt, it never overwrites alt you've already set.
1. Create the file
- 1Open your host's File Manager (Hostinger → File Manager) or connect over SFTP.
- 2Go to public_html/wp-content/mu-plugins/, if the mu-plugins folder doesn't exist, create it.
- 3Create a new file named nexus-image-alt.php and paste the code below, then save.
- 4That's it, mu-plugins activate automatically, no Plugins screen step needed.
<?php
/**
* Plugin Name: Nexus Image Alt Backfill
* Description: Adds descriptive alt text (from the image filename) to any front-end
* <img> missing it, including page-builder / carousel images that Bing & Google
* flag as "alt missing". Only fills EMPTY / absent alt; never overwrites existing.
*/
if (!defined('ABSPATH')) { exit; }
function nexus_alt_from_src($src) {
$path = parse_url($src, PHP_URL_PATH);
if (!$path) { return 'Image'; }
$name = basename($path);
$name = preg_replace('/\.[a-z0-9]+(\.[a-z0-9]+)?$/i', '', $name);
$name = preg_replace('/[-_]+/', ' ', $name);
$name = preg_replace('/\b(scaled|min|copy|final|webp|png|jpe?g|\d{2,4}x\d{2,4}|e\d{6,})\b/i', '', $name);
$name = trim(preg_replace('/\s+/', ' ', $name));
if ($name === '') { $name = 'Image'; }
return ucwords($name);
}
function nexus_fix_img_tag($tag) {
$src = '';
if (preg_match('/\sdata-src\s*=\s*("([^"]*)"|\'([^\']*)\')/i', $tag, $s)) { $src = $s[2] !== '' ? $s[2] : $s[3]; }
if ($src === '' && preg_match('/\ssrc\s*=\s*("([^"]*)"|\'([^\']*)\')/i', $tag, $s)) { $src = $s[2] !== '' ? $s[2] : $s[3]; }
if ($src === '' || stripos($src, 'data:') === 0) { return $tag; }
if (preg_match('/\salt\s*=\s*("([^"]*)"|\'([^\']*)\')/i', $tag, $a)) {
$val = isset($a[2]) ? $a[2] : (isset($a[3]) ? $a[3] : '');
if (trim($val) !== '') { return $tag; }
$alt = esc_attr(nexus_alt_from_src($src));
return preg_replace('/\salt\s*=\s*("[^"]*"|\'[^\']*\')/i', ' alt="' . $alt . '"', $tag, 1);
}
$alt = esc_attr(nexus_alt_from_src($src));
return preg_replace('/<img\b/i', '<img alt="' . $alt . '"', $tag, 1);
}
function nexus_backfill_alt($html) {
if (stripos($html, '<img') === false) { return $html; }
return preg_replace_callback('/<img\b[^>]*>/i', function ($m) { return nexus_fix_img_tag($m[0]); }, $html);
}
add_action('template_redirect', function () {
if (is_admin() || is_feed()) { return; }
if (defined('DOING_AJAX') && DOING_AJAX) { return; }
if (defined('REST_REQUEST') && REST_REQUEST) { return; }
ob_start('nexus_backfill_alt');
}, 1);
2. Confirm it worked
- 1Open your homepage, right-click a previously-flagged image → Inspect, the <img> should now have an alt attribute.
- 2In Bing Webmaster Tools, re-run the scan (or wait for the next crawl), the 'Alt attribute missing' notice count drops to zero.
The best alt still comes from the Media Library or the builder module (a human-written description). This backfill is a safety net that guarantees no image ships without alt, it fills from the filename, so name your image files descriptively for the best result.
To remove it later, just delete nexus-image-alt.php. It's fully reversible and touches nothing else.
Common questions
Will it overwrite alt text I already wrote?
No. It only adds alt to images that have no alt or an empty alt. Anything you've already set is left exactly as-is.
Does it slow the site down?
It adds a light output pass on front-end pages only (never admin/AJAX/REST). The cost is negligible and it works alongside caching plugins.
Why filenames and not AI descriptions?
This is the guaranteed catch-all. For richer alt, keep using the platform's AI alt-text apply for Media Library images, this only fills whatever slips through, like builder-hardcoded carousels.
Related guides
Why Divi/Elementor sites may keep re-flagging alt text even after you fix it.
Fix hundreds of missing alt tags at once, with AI-written descriptions.
A must-use plugin that lets fixes apply even when your host strips the auth header.
We’ll get back within one business day.
