Fetching alternative text from image media URL.

Alt-Text

We can fetch alternative text of an image using its corresponding media URL.

$image_url = "https://add-image-url";
$image_id = attachment_url_to_postid($image_url);
$image_alt_text = get_post_meta($image_id, '_wp_attachement_image_alt', true);

<img src="https://add-image-url" alt= "<?php echo "{$image_alt_text}";?>">

Leave a comment

Your email address will not be published. Required fields are marked *