How to add picture alt attribute code automatic in WordPress? We all know, the picture add alt attributes is conducive the search engine to find the picture.If the alt attribute is appropriate , perhaps the pictures can bring your website a lot of traffic.

However, we may find it is too much trouble to add the picture alt attribute one by one, especially the picture theme site.So is there a method of fully automatic adding to the site pictures alt attribute?

Of cause there is ,you can copy the source code below into the theme function.php file.Then it will add the alt attribute automatic.

function photo_alt($c) {
global $post;//global variable
$title = $post->post_title;//post title
$s = array('/src="(.+?.(jpg|bmp|png|jepg|gif))"/i' => 'src="$1" alt="'.$title.'"');
foreach($s as $p => $r){
$c = preg_replace($p,$r,$c);
return $c;
add_filter( 'the_content', 'photo_alt' );

This address is