Site logo

Archived topic

How to Add Title to IMG tag on Single page?

3 replies · Started by Ralfs on September 11, 2017

Viewing posts 1–4 of 4

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!

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 :)

This archived topic is closed to new replies.