Home Forums ACF PRO ACF + Yoast XML Sitemap Image Inclusion


ACF + Yoast XML Sitemap Image Inclusion

  • Hi all,

    I’ve been working on resolving this issue: Images added into an Advanced Custom Fields PRO image field are not showing in xml sitemap #6480

    TLDR; By default, the Yoast SEO plugin doesn’t pick up images for inclusion into XML sitemaps that have been added via ACF fields (even if you use something like ACF Content Analysis for Yoast SEO)

    After a bit of wrangling (i.e. trying out things that were way more complicated than necessary), I arrived at the solution below:

    function wpseo_xmlsitemap_add_attached_images( $images, $post_id ) { 
    	$attached_images = get_attached_media( 'image', $post_id);
    		foreach($attached_images as $attached_image){
    			$image_arr = array();
    			$image_arr['src'] = $attached_image->guid;
    			$images[] = $image_arr;
        return $images; 
    add_filter( 'wpseo_sitemap_urlimages', 'wpseo_xmlsitemap_add_attached_images', 10, 2 ); 



    From my tests, I can confirm that this works, but would love to have some other people try it out and let me know if you can also replicate success.


Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.