将以下代码添加到主题的functions.php中:

/*
*图片添加alt
*/
add_filter('the_content', 'the_content_img_auto_alt', 999);
function the_content_img_auto_alt($content)
{
    global $post;
    $alt = $post->post_title;
    //清除为空的alt
    $content = str_replace('alt=""', '', $content);
    preg_match_all('/<img (.*?)\/>/', $content, $images);

    if (!is_null($images)) {
        foreach ($images[1] as $index => $value) {
            preg_match('/alt="(.*?)"/', $value, $is_alt);

            if (empty($is_alt[1])) {
                //判断没有alt则添加
                $new_img = str_replace('<img', '<img alt="图片[' . ($index + 1) . '] - ' . esc_attr(strip_tags($alt)) . '"', $images[0][$index]);
                $content = str_replace($images[0][$index], $new_img, $content);
            }
        }
    }
    return $content;
}