Do not add duplicate images from a post to the sitemap
Is your feature request related to a problem? Please describe.
When an image is added multiple times to a post, it's also added multiple times to the sitemap. For example, there might be some cases where users use an image as an introduction to a post, then it's used again further down in the content.
Describe the solution you'd like
I would like image entries not to be duplicated on the sitemap.
Please inform the customer of conversation # 468350 when this conversation has been closed.
Could you please provide a bit more context to this request?
- I created a new post
- added an image block and uploaded a new image
- added a paragraph block
- added a new image block and used the same image as in the first image block (from the media library)
- publish and check sitemap: no duplicate attachment entry.
This does happen when uploading the same image twice, but that is because the filename changes for the second upload attempt. So this is a expected behaviour.
Am I missing something? :)
I am closing this thread due to inactivity.
@Djennez Sorry for not replying earlier, I did not see the activity notification.
I've taken the same steps you mention and I'm able to reproduce the issue. When adding an image from the media library (without re-uploading it, but selecting it from the Media library), the image is added to the sitemap as many times as the image appears in the post:
Source code of the post:

Image duplicates in sitemap source:

Ah, I see, I am able to reproduce this :)
Pinging @jono-alderson at the request of @moorscode to see if this is something that we should do something with.
Yep, this is a bug. Let's fix! :)
It should be easy fix (I've already noticed this issue). We already have "filter" for gallery shortcode: array_unique( $attachments, SORT_REGULAR ); and similar "filter" should be added in method get_images.
Just came across this bug myself (using the latest version of Yoast). The bug still exists. It has been almost 4 years since this issue was reported and confirmed. Will a fix for this ever make it into a release?
still issue in 20.8 even you single times insert in pst still it double entry i think there some options require for sitemap to disable image in sitemap.
Please inform the customer of conversation # 1183227 when this conversation has been closed.