-1

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.

  • 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 Oct 9 '18 at 0:48
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' );
0

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' );

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.