Images are important for engagement with your visitors but the problem with images is that they mean nothing to search engines. The only way search engines can tell what an image is about is by reading the information inside the alt attribute. If you are using WordPress you can easily include images on the page by using the media library. This is where you can select the alt text for the image, but what if you don't have alt text on your images or you forget to enter the alt text? You need a way to automatically populate your image tags with an alt attribute. Below is a WordPress snippet to put into your functions.php file to search your content for images which don't have an alt attribute. If they don't have an alt attribute this function will add it in with a default of the post title. function add_alt_tags($content) { global $post; preg_match_all('//', $content, $images); if(!is_null($images)) { foreach($images[1] as $index => $value) { if(!preg_match('/alt=/', $value)) { $new_img = str_replace('
Share This

We are using cookies on our website

Please confirm, if you accept our tracking cookies. You can also decline the tracking, so you can continue to visit our website without any data sent to third party services.