Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created December 2, 2020 14:13
Show Gist options
  • Save mgibbs189/b630e1d3464695f9f2b83159e57e812d to your computer and use it in GitHub Desktop.
Save mgibbs189/b630e1d3464695f9f2b83159e57e812d to your computer and use it in GitHub Desktop.
FacetWP - force get_the_post_thumbnail() to include a title tag
<?php
// Add to your (child) theme's functions.php
add_filter( 'wp_get_attachment_image_attributes', function( $attr, $attachment ) {
if ( ! isset( $attr['title'] ) ) {
$title = get_the_title( $attachment->ID );
if ( ! empty( $title ) ) {
$attr['title'] = $title;
}
}
return $attr;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment