For better WordPress onpage Seo we need to give our featured images alt and title tags. Unfortunately we can’t use out of the box tools for this (yet).
Featured images alt and title tags with custom code
Plugins that give alt and title tags to images don’t cover featured images. To optimize them you need to use the wp_get_attachment_image_attributes filter. You can put the code bellow to your functions.php
1 2 3 4 5 6 7 8 9 10 11 |
function featured_img_seo_tags ( $attr ) { if( empty( $attr[ ‘title’ ] ) ) { $attr[‘title’] = /*Your img title*/; } if( empty ( $attr[ ‘alt’ ] ) ) { $attr[‘alt’] = /*Your img alt*/; } return $attr; } add_filter( ‘wp_get_attachment_image_attributes’, ‘featured_img_seo_tags’, 10, 2 ); |
Featured images alt and title tags with a plugin
We are working on a flexible and customizable plugin that will make this task a piece of cake. Here is a sneak preview of it’s options page.