WordPress

Adding Alt Tags to WordPress Featured Images

In your WordPress themes, follow the steps below to add alt tags to featured images in the topic (single.php).

Many WordPress themes do not have alt and title tags for featured images. You can add these tags, which are important for SEO, to the single.php page by making the following edit.

Adding Alt Tags to Featurd Images

  • Open your theme’s single.php file.
  • Find the lines get_the_post_thumbnail or the_post_thumbnail by searching for them.
  • The line of code you find should be similar to the one below.
  • <?php echo get_the_post_thumbnail($post->ID, ‘large’); ?>
  • Replace this code string directly with the code below or edit it manually according to your own code.
  • <?php echo the_post_thumbnail( ‘large’, array( ‘alt’ => get_the_title(), ‘title’ => get_the_title() ) ); ?>
  • By re-uploading the single.php file you edited, you will have added the alt and title tags.

Note: In some themes, this code line may be in a different file instead of single.php. If you cannot find it in single.php, you can find the code by searching all the files of the theme.

Note2: If your theme has this feature, you do not need to follow the above explanation. In order to understand whether your theme has this feature, you can check the alt tags of your featured image in any of your content by writing a description in the Alternative text section.

For more, check out the_post_thumbnail on WordPress Developer Resources.

Leave a Comment

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

Scroll to Top