Skip to content

Add The Title Attribute To Featured Image in WordPress

The title attribute for the WordPress featured post has been removed for a while, but you can get it back with the wp_get_attachment_image_attributes filter which can add the HTML attribute markup back in, add to your functions.php file…

 

add_filter( 'wp_get_attachment_image_attributes', 'tl_add_img_title', 10, 2 );
// Add title attribute to featured image
function tl_add_img_title( $attr, $attachment = null){
	$attr['title'] = get_post( $attachment->ID )->post_title;
	return $attr;
}

The title attribute was removed due to accessibility issues – however is some instances you may need it for lightbox overlay purposes.

2 Comments

  1. Roman on May 11, 2019 at 11:59 am

    Thanks a lot but i could not get it. Is attribute visible or not?

  2. George on December 7, 2018 at 10:17 am

    Thank you very much for this one :). The title attribute has another two advantages, first to say, IE does not display the alt tag of images, but it does display the title tag. God alone knows why! That’s the biggest cross-browser failure of all times (besides IE 6 maybe). But secondly and not to forget, it’s another beautiful place where we SEO people can add an additional instance of our focus keyword/phrase.

Leave a Comment





Scroll To Top