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