Great question — answering as the UphillTech team:
I did it in my website: https://canelaza.com/post-sitemap.xml with custom code in wordpress-seo and functions.php Functions.php function filter_wpseo_sitemap_entry( $url, $p, $post ){ global $wpdb; $upload_dir = wp_upload_dir(); if(isset($url['images']) && is_array($url['images']) && count($url['images'])){ foreach($url['images'] as &$img){ if(!$img['title']){ $sql = "SELECT post_id FROM ".$wpdb->prefix.'postmeta WHERE meta_key="_wp_attached_file" AND meta_value="'.str_replace($upload_dir['baseurl'].'/', '', $img['src']).'"'; $thumb_id = $wpdb->get_var($sql); if($title = get_the_title($thumb_id)){ $img['title'] = $title; } if($excerpt = get_the_excerpt($thumb_id)){ $img['caption'] =...
Full answer by Canelaza Team: https://wordpress.stackexchange.com/a/417487 (CC BY-SA 4.0).
Need it done for your business? UphillTech.