I’m attempting to remove the title attribute for post thumbnails (on certain posts), and I assume the get_image_tag filter is the way to do this. However, what I’ve got so far isn’t working. What do I need to change to make this work? My code:
add_filter('get_image_tag', 'image_no_title');
function image_no_title($title) {
$title="";
return $title;
}
And the relevant function (from wp-includes/media.php):
function get_image_tag($id, $alt, $title, $align, $size="medium") {
list( $img_src, $width, $height ) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);
$class="align" . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
$class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
$html="<img src="" . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" title="' . esc_attr($title).'" '.$hwstring.'class="'.$class.'" />';
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
return $html;
}
3 Answers
Thanks to Rarst pointing out that I was in the wrong place, I did some more digging and ended up with this:
add_filter('wp_get_attachment_image_attributes', 'wpse_19029_no_image_title');
function wpse_19029_no_image_title ($attr)
{
unset($attr['title']);
return $attr;
}