Temanızın function dosyasını açın ve ekleyin:
function add_alt_to_images_if_missing( $attr, $attachment = null )
{
if($attr['alt']=='')
{
$attr['alt']=trim( strip_tags( $attachment->post_title ) );
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes','add_alt_to_images_if_missing', 10, 2 );Çalışmazsa, aşağıdaki kodları deneyin:
function add_alt_tags($content)
{
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images))
{
foreach($images[1] as $index => $value)
{
if(!preg_match('/alt=/', $value))
{
$new_img = str_replace('<img', '<img alt="'.$post->post_title.'"', $images[0][$index]);
$content = str_replace($images[0][$index], $new_img, $content);
}
}
}
return $content;
}
add_filter('the_content', 'add_alt_tags', 99999);Bu şekilde tüm görsellere yoksa alt etiketi ekler ve başlıktan çeker.