images - Alt attribute is not showing while the value is given in Media

admin2025-01-07  6

Here is my website / I'm trying to perform SEO on it and for this I need to set alt attribute for each image. Even I have given it in media but instead, it is not showing when I look it in inspect element or view source. I have found an article related to this alt, title tags not showing but it did not help me as its answer was specific to the theme. I'm using Food & Cook theme for my website /. Can anyone help me please.

Here is my website http://www.taramesh.ae/ I'm trying to perform SEO on it and for this I need to set alt attribute for each image. Even I have given it in media but instead, it is not showing when I look it in inspect element or view source. I have found an article related to this alt, title tags not showing but it did not help me as its answer was specific to the theme. I'm using Food & Cook theme for my website http://dahz.daffyhazan.com/food-cook/. Can anyone help me please.

Share Improve this question asked Sep 20, 2017 at 10:50 majidmajid 111 silver badge1 bronze badge 2
  • Adding alt text in the media library will not affect any pages that you have already inserted the image into. You will need to go to each page and edit the image directly in the content to add the alt text. – Jacob Peattie Commented Oct 9, 2018 at 0:48
  • For my $0.02 I could see the value of adding alt att in media library also updating it everywhere—unless there is a different value already added at that post level; likewise updating the attribute at the post level would only affect that page and not change value in media library! Woo-hoo. – Drewdavid Commented Apr 30, 2021 at 21:43
Add a comment  | 

2 Answers 2

Reset to default 0

For post and page content, when an image is added from the media library an image tag is generated with the alt tag being whatever the alt text in the media library was when the image was inserted. Since the image is added as HTML with the alt tag, updating the alt text in the media libray won't update it on the page (otherwise it would need to scan and update all your content whenever an image description is changed).

To change the alt text of an image you'll need to edit the page it is on, and select and edit the image there. That will update the alt text in the page source.

For images output by templates or custom fields then the alt text might not be updating because the template was never coded to output the alt text. A template would need to get the alt text by using get_post_meta():

echo get_post_meta( $attachment_d, '_wp_attachment_image_alt', true);

Or by using the wp_get_attachment_image() function, which will include the alt text in its output:

echo wp_get_attachment_image( $attachment_id, 'full' );

To change the alt text of an image you'll need to edit the page it is on, and select and edit the image there. That will update the alt text in the page source.

For images output by templates or custom fields then the alt text might not be updating because the template was never coded to output the alt text. A template would need to get the alt text by using get_post_meta():

echo get_post_meta( $attachment_id, '_wp_attachment_image_alt', true);

Or by using the wp_get_attachment_image() function, which will include the alt text in its output:

echo wp_get_attachment_image( $attachment_id, 'full' );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259533a596.html

最新回复(0)