After countless unsuccessful attempts yesterday, I even dreamed very ambiguously about it, but I managed in the morning to solve and put an alt text for the thumbnail.

WARNING:Use a test site for your theme if you do this.

https://my.wealthyaffiliate.com/training/using-mal...

Go to Appearance, Editor, Choose Header.php and add the code

<?php

$img_id = get_post_thumbnail_id($post->ID); // This gets just the ID of the img

$image = wp_get_attachment_image_src($img_id, $optional_size); // Get URL of the image, and size can be set here too (same as with get_the_post_thumbnail, I think)

$alt_text = get_post_meta($img_id , '_wp_attachment_image_alt', true);

$perm = get_permalink($post->ID);

?>

<a href="<?php echo($perm); ?>" title="<?php the_title(); ?>"><img src="<?php echo($image[0]); ?>" width="<?php echo($image[1]); ?>" height="<?php echo($image[2]); ?>" class="alignleft" alt="<?php echo $alt_text; ?>" /></a>

I put it in my Header.php after :

<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );

$url = $thumb['0'];

?>

Now, I test it again with https://varvy.com/

Victory!

All my features images from my Homepage have an alt text!

See my other training here

https://my.wealthyaffiliate.com/dorina62/training:




Join the Discussion
Write something…
Recent messages
SadieChan Premium
Thanks for the training, Dorina. Need to absorb this slowly.
Reply
johnwnewman Premium
Nice work! :-)
Reply
T1967 Premium
:-)) ta hun
Reply
janmar Premium
Thank you for the training.
Reply
dorina62 Premium
You welcome!
Reply
Loes Premium
Hi Dorina, this is very advanced for a lot of members here, you should advise people to open a test website, before doing this stuff on their regular websites.
Reply
dorina62 Premium
Yes, I did this on page 4! Thanks!
Reply
Loes Premium
Sorry, I missed that:)
Reply
dorina62 Premium
Not a problem!
Reply
Top