This will return a fully formatted HTML <img ... >
tag.
$thumb_id = $post->ID;
$pictureLink = get_the_post_thumbnail($thumb_id, 'medium');
What function can I use to get the ‘src’ tag value?
I tried some other WP functions for attachments but these did not return anything useful for some reason.
I will accept a WP function or a parser that will extract the src
tag’s value.
Update:
Parser that will extract the src
tag’s value.
$doc = new DOMDocument();
$doc->loadHTML($pictureLinkHtml);
$xpath = new DOMXPath($doc);
$pictureLink = $xpath->evaluate("string(//img/@src)");
You can do this a lot easier than parsing it. First you need to get the attachment ID from the post ID. then you can grab the source which includes the URL, width and height. Here is more information.
You could use:
See wp_get_attachment_image_src reference.