I have added alt tags, title and description on all the images on my website but none are showing when I check them in the inspect element tool in chrome or firefox.

Here's a screenshot:

enter image description here

And here's the screenshot of inspect element of the same image:

enter image description here


It actually depends upon how the image is shown in the template. If it is shown using a function like the_post_thumbnail() which returns complete html string to show image with alt then there should be no problem but if image is shown by only fetching URL then it depends how it is displayed .

For example, below is snippet which is fetching image directly on a WP image attachment page:

//fetching attachment image src url 
$attachment_size = apply_filters( 'abc_attachment_size', array( 960, 960 ));
$image_attributes = wp_get_attachment_image_src( $post->ID, $attachment_size); 

if( $image_attributes ) {
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>

In above code, we are displaying image from data we fetched individually, here since alt is not used , it will not show alt. Similarly in your case, I am assuming its because theme has no alt specified, its not being shown there.

Also, I tried downloading your theme file but was reported as malicious by browser so I left it.

| improve this answer | |
  • So there's no way to show alt and title tags if they aren't present in the theme? – Rahul Jan 24 '17 at 9:10
  • As said, it depends how it is implemented in the theme. From output you shared, I assume its some theme specific location and can't be answered without seeing the code for that particular location. You may ask theme developer to guide you or share the code here to get exact solution. – Saahib Jan 24 '17 at 9:33

To make the alt tag appear with that image, you have to modify the theme. The code which outputs the image is located in mediatraining/inc/modules/trainers/shortcode.php. On line 13 the image is loaded form the options:

$img = mbtheme_get_option( 'lead-trainer-image' );
$img_url = $img[ 'url' ];

On line 27 it is used then:

<img src="<?php echo esc_url( $img_url ); ?>" />

So to be abnle to have the alt tag here you could try something like this on line 27:

<img src="<?php echo esc_url( $img_url ); ?>" alt="<?php echo esc_attr( $img['alt'] ); ?>" />

This is not tested and I am not sure about the $img['alt'] part, because I don't know what is exactly saved there. Alternatively try $img['title'] or try dumping $img to see if the alt text can be found in there.

| improve this answer | |

I found a script, try if this works for you. Add this in your theme's functions.php file

function isa_add_img_title( $attr, $attachment = null ) {

    $img_title = trim( strip_tags( $attachment->post_title ) );

    $attr['title'] = $img_title;
    $attr['alt'] = $img_title;

    return $attr;
add_filter( 'wp_get_attachment_image_attributes','isa_add_img_title', 10, 2 );
| improve this answer | |
  • Here's a link to the entire theme files if you want to take a look. ufile.io/0e683 – Rahul Jan 24 '17 at 8:20

It appears that (as of version 4.7) the alt attribute is no longer automatically displayed. There are plugins that restore this functionality (eg. https://wordpress.org/plugins/auto-image-alt/). If you have SEO in mind these are useful only to some extent because the attribute is added by JavaScript.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.