Fix Missing Image Title Attributes in Astra Theme

If image title attributes you entered in WordPress are missing from the rendered HTML, your theme or an image filter may be removing them. I ran into this issue while working with the Astra theme and found a way to add the attributes back to images generated from the WordPress Media Library.\r\n\r\nOne important distinction: an image title attribute is not a substitute for descriptive alt text and should not be added just to improve SEO. The title attribute may appear as a tooltip in some browsers, while useful alt text supports accessibility and helps search engines understand an image.


I wanted to restore the image title text for visitors who expect to see it on hover. The following child-theme snippet adds the WordPress Media Library attachment title to generated image markup. Use it only if you specifically want that tooltip behavior; it is not an SEO requirement.

img title attribute - astra theme

How to Add Image Title Attributes in the Astra Theme

If you use an Astra child theme and want to add a title attribute to images rendered through WordPress, add the following code to your child theme's functions.php file. Back up the file first, or use a code-snippet plugin configured to run PHP snippets, so a syntax error does not take down your site:

  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.

After saving, inspect a rendered image in your browser's developer tools and confirm that it contains a title attribute. Some desktop browsers may show its text as a tooltip on hover, but this behavior varies by browser and should not communicate essential information.

For image SEO and accessibility, prioritize concise, accurate alt text for meaningful images. Use an empty alt="" for purely decorative images, and do not repeat keywords or copy the same text into every image attribute.