Use Filename for Alt and Title Tags

The alt tag already takes the filename but if for some reason you need to replace hyphens with spaces and include a duplicate title of the alt tag you can do something like:

function wpse_120228_seomadness($html, $id, $caption, $title, $align, $url, $size, $alt) {

    $alttitle = str_replace('-', ' ', $alt);
    $img      = get_image_tag($id, $alttitle, $alttitle, $align, $size);
    $html="<a href="" . esc_attr($url) . '">' . $img . '</a>';

    return $html;
}
add_filter( 'image_send_to_editor', 'wpse_120228_seomadness', 10, 9 );

This will only affect images inserted into the editor after the code is added and not images already on your site.

Leave a Comment