Created
September 12, 2022 10:39
-
-
Save iworks/f846d14df92b843da315e5002baff6d0 to your computer and use it in GitHub Desktop.
Add post title as a alt for thumbnail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( | |
'wp_get_attachment_image_attributes', | |
function( $attr, $attachment, $size ) { | |
if ( ! is_singular() ) { | |
return $attr; | |
} | |
if ( isset( $attr['alt'] ) && ! empty( $attr['alt'] ) ) { | |
return $attr; | |
} | |
$attr['alt'] = get_the_title(); | |
return $attr; | |
}, | |
10, | |
3 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment