Change featured image alt tag in WordPress

Change featured image alt tag in WordPress

Image alt tag (attribute) is useful because it describes your images and make users easier to find relevant content while searching on Google and other search engines.

If you run a WordPress website, you can of course add alt tags manually for each image but if you have a lot of content you will probably want an easy way to automatically set alt attributes at once. This particular example will show how you can change all your featured image (thumbnail) alt tags to its specific post title.

Introducing post_thumbnail_html WordPress filter hook

We are just using few lines of code in post_thumbnail_html WordPress filter hook. Note that your image alt tags won’t be physically changed in media library, the snippet will just modify HTML output on the frontend of your site.

That’s all folks! You just need to paste this snippet somewhere inside your theme functions.php file. Feel free to try and give us a feedback.

Bojan Petrovic

Co-founder and WordPress developer at Meks. He has been involved in the business since 2009. creating themes, plugins and services on top of WordPress, continuously aiming to choose best approaches and work smarter, not harder.


Leave a comment

Leave a Reply

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