If you are bulk editing your images to reduce them in size, you may have need to back up or export out all your Alt text for the images on the website. We couldn’t find a free tool to find Alt Text for Images on our website, so we wrote a script to pull the data from phpMyAdmin.
Reducing image size can improve the website performance and loading speed, which is a core factor for SEO. Google ranks by mobile loading speed.
Script to Find Alt Text for Images in phpMyAdmin
The below query will pull out any images that have alt text applied. Note: it doesn’t show the images without any alt text.
SELECT a.ID, a.post_title, b.meta_value ‘Alt Text’, a.post_mime_type ‘File Type’, a.guid ‘Post URL’
FROM `wp_posts` a, `wp_postmeta` b
WHERE
a.id = b.post_id
and a.post_type = ‘attachment’
and b.meta_key=’_wp_attachment_image_alt’
You can then export the results to a CSV file for exiting etc. You may need to edit the table names depending on the formatting of the database.
To check the Alt Text on a individual URL in phpMyAdmin
To check the alt text on a individual URL, use the below query and just replace the URL in the quotes below:
SELECT a.ID, a.post_title, b.meta_value ‘Alt Text’, a.post_mime_type ‘File Type’, a.guid ‘Post URL’
FROM `wphf_posts` a, `wphf_postmeta` b
WHERE
a.id = b.post_id
and a.post_type = ‘attachment’
and b.meta_key=’_wp_attachment_image_alt’
and a.guid=’https://agiledigitalstrategy.com/wp-content/uploads/2020/11/Sole-Logo.png‘
There are software plugins/packages that may allow you to replace images and keep the meta data including Alt text intact. This is just a handy script to have.