Update Image ALT Attribute Automatically on WordPress

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.

While dealing with Blog Posts or Pages you might forget to take care of the ALT tags when images are getting uploaded to the Post or Page. Or this scenario happens when you are bulk uploading images from frontend or backend. It may not affect your frontend but it will create serious issues when you are dealing with SEO.

ALT tag helps Search Engine bots to understand an image. Search Engine bots can’t see and they need a clue to understand the image. If bots can understand your images, they will give you good ranks for the related keywords. And you can drive huge traffic from Image based Search Engine like Google Image search.

All you need to do is, add proper alt tags to your images. The other thing that matters for SEO is Title tag. But it is less important then tag. So let’s get ahead. I am going to tell two different ways to update your image tag.

The Manual Approach to Update ALT

Generally you can add tag when you upload a new image. WordPress uploader makes it easier.

Image ALT From Media Library

Media Library will give you to add or edit alt tag once the image is uploaded to server. Update a text that is not lengthy and should be perfect seo keyword. That’s it. WordPress will do the rest for you.

Automatic Approach to Update ALT

When you are dealing with a lot of images like a really lots of images its better to use some code instead of getting into media library and updating tag manually.

Edit you theme functions.php or any file you have added to add custom codes in your custom plugin and paste the follwing code.

I will explain both the filters, the first filter image_send_to_editor does the job of updating image alt whenever a new image is updated via Media Library.

The second filter wp_get_attachment_image_attributes will come into action when a image is called for frontend display. While returning the attachement for post, page or any custom post type post, this filter will check for images that are being return with a blank alt, it captures those images add the alt tag using the title of the image and returns the image to frontend function.

Isn’t that so simple. After adding above code go for a seo checkup, your image alt section will defineitly have a green tick mark.

Happy Coding 🙂

dipak Written by: