Maybellyne. This is the code i used but i cannot see the gallery image URL’s in the sitemap
function add_gallery_images_to_sitemap( $images, $post_id ) {
// Get the post content
$post_content = get_post_field( 'post_content', $post_id );
// Look for gallery shortcodes
if ( has_shortcode( $post_content, 'gallery' ) ) {
// Extract all gallery shortcodes
preg_match_all( '/\[gallery.*ids=.(.*).\]/', $post_content, $matches );
if ( isset( $matches[1] ) ) {
foreach ( $matches[1] as $match ) {
// Get the image IDs
$image_ids = explode( ',', $match );
foreach ( $image_ids as $id ) {
$image = wp_get_attachment_image_src( $id, 'full' );
if ( $image ) {
$images[] = array(
'src' => $image[0],
'title' => get_the_title( $id ),
'alt' => get_post_meta( $id, '_wp_attachment_image_alt', true ),
);
}
}
}
}
}
return $images;
}
add_filter( 'wpseo_sitemap_urlimages', 'add_gallery_images_to_sitemap', 10, 2 );
“You can also use the filter,?wpseo_sitemap_urlimages
?to register images to appear on the sitemap.” I see the image URL’s in the HTML output but not in the sitemap. I’ve missed something? Not using blocks!