Add Missing Title Attribute to Images - Astra Theme

By default the Free WordPress Astra Theme does not display the title attribute you add to your images. Img title attributes or image title tags are useful for SEO. It can be a real bummer to find your images are not showing the title attribute, especially when you have taken the time to enter and optimize them.

So I ventured out to fix the issue, and following is my simple solution.

img title attribute - astra theme

How to add Missing Title Attribute to Images

To add the Missing Title Attribute back to your images for the Astra WordPress theme:

  1. Login to your WordPress site
  2. Navigate to Appearance > Theme File Editor and open your Astra child functions.php file.
  3. Add the following code snippet to the bottom of the file.
    // Add missing Title Attribute to Images - Astra Theme
    function add_image_title_attribute( $attr, $attachment, $size ) {
    $attr['title'] = trim(strip_tags( get_post_field('post_title', $attachment->ID ) ));
    return $attr;
    }
    add_filter('wp_get_attachment_image_attributes', 'add_image_title_attribute', 10, 3);
  4. Click Update to save the file.

If all went well, your <img title="" attributes should now be displaying on your Astra WordPress theme when you hover over the images while viewing your posts and pages.