Images in the XML sitemap

Google reports content types submitted in your XML sitemaps in Google Search Console (formerly Google Webmaster Tools).

content types in Google Webmaster Tools

Quick Links

Why are images reported? I have images excluded in the settings!

No. You haven't. It's simply not possible in the plugin settings. But the problem lies with how WordPress deals with images and the naming around that, it's not just you who gets confused. When you upload an image, WordPress automatically creates a post of the type "attachment" in the database, and the corresponding URL for that. It calls this the "media" post type.

You can exclude the media post type from your XML sitemaps settings (and in most cases that's probably a good idea):

This setting won't prevent Google from indexing the actual image URLs. What Google reports in Google Search Console (formerly Google Webmaster Tools) are the actual image URLs, not the attachment URLs. Yoast SEO automatically enriches your XML sitemap with the image(s) from a post and that's why Google reports on them.

Why is there a difference between submitted and indexed?

This could be due to all sorts of reasons, but especially for images it's generally not something to worry about. It might be that Google doesn't find the images interesting enough, big enough or otherwise has decided it doesn't need to index them. If it doesn't throw an error, it's not your fault.

It can actually be the other way around too: if you haven't added all the videos or images on your site to an XML sitemap, it can index more than you submitted, as is clearly shown from the Video example in the above screenshot.

What if I really need to remove images for the sitemap?

The wpseo_xml_sitemap_img filter allows you to modify the sitemap images and the code below will remove the images when the sitemap updates. You can force an update by disabling and enabling the sitemaps.

/* Remove Images From Yoast Sitemap */
add_filter( 'wpseo_xml_sitemap_img', '__return_false' );

What if the image URL is wrong?

The wpseo_xml_sitemap_img_src filter allows you to manually change the image URL. The code below will replace the URL when the sitemap updates. You can force an update by disabling and enabling the sitemaps.

function wpseo_cdn_filter( $uri ) {
  return str_replace( '', '', $uri );
add_filter( 'wpseo_xml_sitemap_img_src', 'wpseo_cdn_filter' );

What if I want to add images in the sitemap?

Some themes or pagebuilder modules may not show the images on the sitemap. You may need to add them via a filter: wpseo_sitemap_urlimages. This filter will then register images to appear on the sitemap.

If you are not sure how to use the filter you may wish to speak with your theme or plugin developer. You may also need to hire a Yoast Partner

What are those videos you have there?

If you have videos on your site, you might want to submit an XML video sitemap to Google too. Our Video SEO plugin can take care of that and lots of other video optimization for you!

Was this article helpful? ·