Created
December 2, 2020 14:13
-
-
Save mgibbs189/b630e1d3464695f9f2b83159e57e812d to your computer and use it in GitHub Desktop.
FacetWP - force get_the_post_thumbnail() to include a title tag
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 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