You can use the 'wp_get_attachment_image_attributes' hook
add_filter(
'wp_get_attachment_image_attributes',
'image_attributes',
20,
2
);
function image_attributes( $attr, $attachment )
{
// Get post parent
$parent = get_post_field( 'post_parent', $attachment );
// Get post title
$title = get_post_field( 'post_title', $parent );
if ( is_single( $parent ) ) {
$attr['alt']=$title;
}
return $attr;
}
Or Check Out my newuse this plugin
Its now on WordPress plugins directory. The Alt Manager plugin is a simpleWordPress plugin thatbulk changes WordPress images Alt and Title attributes text and generate empty values on your (PagesHomepage – Pages – Posts – Blog ) separately to your website name or[Free Version] (post orProducts – Shop page – Custom Post Type – Custom Post Type archive page)[Premium Version] separately to several dynamic related values, This plugin is a full solution for generating alt and title values.This
This Plugin bulk changes images Alt and Title attributes immediately on your website front end, you dontdon’t need to change image info on media library. https://wordpress.org/plugins/alt-manager/