Created
May 4, 2017 11:37
-
-
Save markusvonplunkett/7c119c1e36a497bac31aaa26e2a17383 to your computer and use it in GitHub Desktop.
Display a fallback Alt tag if none is present. Ideally clients should be instructed on how to add media with the relevant alt tags.
This file contains 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
/** | |
* Display a fallback Alt tag if none is present. Ideally clients should be instructed on how to add media with the relevant alt tags. | |
*/ | |
function sz_wp_get_attachment_image_attributes ( $attr, $attachment, $size ) { | |
global $post; | |
if ( empty($attr['alt']) ){ | |
// $attr['alt'] = 'hardcord fallback'; | |
// $attr['alt'] = get_field('heading', $post->ID); | |
// $attr['alt'] = $post->post_title; | |
} | |
return $attr; | |
} | |
add_filter('wp_get_attachment_image_attributes', __NAMESPACE__ . '\\sz_wp_get_attachment_image_attributes', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment