Skip to content

Instantly share code, notes, and snippets.

m-thomson /
Last active June 23, 2023 14:12
WP All Import duplicate image problem

When an image is imported, the name used in the media library is derived from the URL "basename". This can cause problems, especially when using the option "Search through the Media Library for existing images before importing new images". For example, even though they are different images, these URLs all have the same "basename" (in bold). They will generate the same file my-image.jpg in the WordPress library:

http:// my-image.jpg
http:// my-image?id=1
http:// my-image.jpg

The solution is to put this PHP code in your function editor:

function fix_img_url($url){