Archived topic
How to Add Title to IMG tag on Single page?
3 replies · Started by Ralfs on September 11, 2017
Hi,
How to add Title tag in IMG tag on Single post page? I want right after https://puu.sh/xxIe6/27593a3458.png . I tried restore-image-title.1.5 plugin, but id did nothing. Let me know!
This has actually been applied to core in the next release.
However for now, you can do something like this: https://gist.github.com/generatepress/14851417f7bcc7620737e2e22d2c2f98
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!
That's a perfect solution :)