Retrieve alternative text of an Image using image url or id in wordpress

To get alternative text of an image in WordPress do the following,

$image_url=”Your image url”;
//To get image id
$image_id = get_attachment_id_from_src($image_url);
//Now using image id we get alternative text
echo get_post_meta($image_id, ‘_wp_attachment_image_alt’, true);

Hope this information is useful! Enjoy and save your time.

Comments are closed.
* required
We no more support old browsers. Kindly upgrade to IE 8, IE 9 or Google Chrome or any modern browsers.