Automatically add alt tags to wordpress featured images

I was working on a site recently that had a few thousand images imported to wordpress after a drupal conversion, these images were set as the featured image for the imported posts. Because of the way the old site was constructed, these images had no meaningful names.

You can use the mysql query below to set the alt tags of your featured images to the name of the post.

This query assumes that no alt tag data currently exists, if you have existing alt tags, you will need to use an update query instead. Also note this only sets the alt data for images set as featured images for posts.

4 thoughts on “Automatically add alt tags to wordpress featured images

  • Sally says:

    Hi Greg. Thanks for writing this useful code. I was just wondering where exactly to insert it?

  • Mike says:

    Will this work for pages too? My current theme doesn’t seem to display the alt text or title even when those fields have data in the media library.

  • Prateek says:

    How do you do the same for Featured Image titles? instead of alt tags.

    I mean “Automatically add titles to wordpress featured images”. Amy help would be appreciated.

    Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *