The code you provided is just adding ALT tag, which I had already, but I wnated to add additional title tag.
I managed to do it by editing ALT to TITLE
add_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’, 10, 2);
function tu_featured_image_alt( $attr, $attachment ) {
remove_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’);
$attr[‘alt’] = $attachment->post_title;
return $attr;
}
changed to
add_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’, 10, 2);
function tu_featured_image_alt( $attr, $attachment ) {
remove_filter(‘wp_get_attachment_image_attributes’,’tu_featured_image_alt’);
$attr[‘title’] = $attachment->post_title;
return $attr;
}
And it worked. Is this good solution? I am no develoepr so not sure! 🙂
Let me know!