• Resolved pawellabaj

    (@pawellabaj)


    There is no images in generated sitemap.

    I believe this is because of Photonic plugin used to handle images. I want to add a wpseo_sitemap_urlimages filter to add at least featured images in sitemap.

    I’ve tried to implement the filter as follow:

    function filter_wpseo_sitemap_urlimages( $images, $post_id ) { 
      array_push($images, 'https://www.foto.labaj.com.pl/wp-content/uploads/2021/07/P7120044_1800x2400-G-SI.jpg');
      return $images; 
    }; 
    add_filter( 'wpseo_sitemap_urlimages', 'filter_wpseo_sitemap_urlimages', 10, 2 );

    No image is present in https://www.foto.labaj.com.pl/post-sitemap.xml even after purging caches.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Michael Ti?a

    (@mikes41720)

    Hi,

    We do know that if you’ve added your images to the default content area with the WordPress block or classic editor, this will be parsed and included in the sitemap.

    However, some themes or page builder modules may not show the images on the sitemap. Since you’ve mentioned that you are using another plugin to handle images, you may need to add them via the wpseo_sitemap_urlimages filter like you’ve mentioned. You can learn more about it here – https://yoast.com/help/images-in-the-xml-sitemap/

    If the filter isn’t working as expected, we suggest you reach out to a developer or programmer that can help you with implementing this filter on your site.

    Thread Starter pawellabaj

    (@pawellabaj)

    I’ve added the code that I paste in the snippet to functions.php of the theme I use.

    I’m, sure that functions from that file are being called as other “modifications” work.

    As I understand how the filter should work, at least one image should be added to every post I have in a sitemap. However, there are no images at all in the sitemap.

    Is there any other “mechanism” that could remove images?

    Plugin Support Md Mazedul Islam Khan

    (@mazedulislamkhan)

    It’s odd that Yoast SEO should automatically add the featured image or an image from the default content editor to the XML sitemap. Can you please confirm whether you’re adding images on the posts as a featured image or to the default content editor?

    That said, we have tested the relevant code snippet given here that shows the implementation of wpseo_sitemap_urlimages and see that it’s not working. We appreciate you for bringing this to our attention. We have submitted an issue report to our content team to update the relevant code snippet.

    In the meantime, you’ll need to add the following code snippet to add the images manually to the XML sitemap.

    function filter_wpseo_sitemap_urlimages( $images, $post_id ) {
      array_push($images, ['src' => 'https://www.example.com/wp-content/uploads/extra-image.jpg', 'title' => get_the_title( $post_id )]);
      return $images;
    };
    add_filter( 'wpseo_sitemap_urlimages', 'filter_wpseo_sitemap_urlimages', 10, 2 );
    

    Note: in the updated code snippet, we had to add the image title as well. Otherwise, the image won’t appear in the XML sitemap. So, we had to use an additional array ['src', 'title'] inside the array_push() to make it work. Currently, the title will be the post title for the relevant image. If you’d like you can set it whatever you’d like.

    Thread Starter pawellabaj

    (@pawellabaj)

    Hi @mazedulislamkhan ,

    When I updated the code with passing ['src', 'title'] the image appeared in the sitemap.

    Now I can work on adding images I need.

    Thanks for help

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wpseo_sitemap_urlimages filter doesn’t work’ is closed to new replies.