how to set alt tag in images of post content in wordpress

You are working with the wordpress and post many article in your wordpress blog, in some article you are using the images and you insert it in the post content, when you upload the images then its go to the media gallery and then you inset it post and set as feature image, google can not fetch the images directly in its list, we need to set the alt tag in the images and google can read the alt tag from the images and then index that image in its list. once the alt tag is set in the image than google get idea regarding the image and then its set it and display in the images when any user search images.

Now, you did not set the alt tag when you insert the images in the post content and now there are many post in the blog, so its not possible to edit it one by one and set the alt tag to the image. Don’t worry i implement very easy way to set the alt tag in all the missing images.

function add_alt_tags_to_images($post_content)
global $post;
$post_content = str_replace('alt=""','alt="'.$post-&gt;post_title.'"', $post_content);
return $post_content;
add_filter('the_content', 'add_alt_tags_to_images', 99999);

You can put the above code in you function.php file which is in the theme folder of your wordpress blog. once you put this code in the function.php and run the blog then its set post title as the image alt tag in your site. Hope this will save your time and you enjoy it.