Created
February 17, 2020 22:13
-
-
Save ashleycam3ron/c76a35f787cb36d0af87bfe92dcb8dfb to your computer and use it in GitHub Desktop.
Add Title and Alt Attribute to WordPress Image the_post_thumbnail
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
<?php /* Add Title and Alt Attribute to WordPress Image the_post_thumbnail */ | |
function ac_add_img_title( $attr, $attachment = null ) { | |
$img_title = trim( strip_tags( $attachment->post_title ) ); | |
// or get the title instead of image title $attr['title'] = the_title_attribute( 'echo=0' ); | |
$attr['title'] = $img_title; | |
$attr['alt'] = $img_title; | |
return $attr; | |
} | |
add_filter( 'wp_get_attachment_image_attributes','ac_add_img_title', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment