Skip to content

Instantly share code, notes, and snippets.

@markusvonplunkett
Created May 4, 2017 11:37
Show Gist options
  • Save markusvonplunkett/7c119c1e36a497bac31aaa26e2a17383 to your computer and use it in GitHub Desktop.
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.
/**
* 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