Archived topic
Set image alt tag to post title-image title
5 replies · Started by Michael on July 15, 2018
Could you help me out with a function that would do that, so I don't have to dig around in the theme?
So the format of the image alt tag would be "name of post - name of image" ?
Hi there,
Have you tried setting the Alt tag to the image when setting it as your featured image? It should allow you to set it to whatever you like :)
Hi,
This is for the few thousand images that I haven't set tags for Tom ;)
Ah got it. Try this:
add_filter( 'post_thumbnail_html', 'tu_featured_image_auto_alt', 10, 5 );
function tu_featured_image_auto_alt( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
$attr['alt'] = get_the_title( $post_id );
return $html;
}
Thanks Tom, really appreciate your support. :)
No problem! :)