This solution will automatically add the post title as alt attribute to the image(s) of that particular blog post.
Add Post Title To Missing Alt Tags WordPress Images
1. Log into your WordPress Dashboard.
2. Click on Appearance.
3. Then click on Theme Functions file (functions.php).
4. Now paste this set of code into the functions.php.
function add_alt_tags($content)
{
global $post;
preg_match_all('/<img (.*?)/>/', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);
5. Click Update File button.{
global $post;
preg_match_all('/<img (.*?)/>/', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);
Warning: Functions.php is very sensitive.
If you paste your code wrongly in this file, you could be locked out of your own site (you cannot log in or log out) and in addition, your site cannot be accessed.
Note: If this problem happens to you, then read this post: WordPress Function.php Error: Cannot Log In And Site Disappear.
Related Tutorials:
* Tools To Find Images With Missing Alt Tags
* Plugin To Find And Delete Unused Images In WordPress