XML Sitemap - Wrong image URL in post-sitemap.xml
chrome-cgi opened this issue · comments
Describe the bug
When the home URL contains path, such as:
https://example.com/wp
and the post contains custom/external image,
<img src="/not_under_wp/img.png">
the image URL in post-sitemap.xml is generated incorrectly:
<image:image>
<image:loc>https://example.com/wp/not_under_wp/img.png</image:loc>
</image:image>
Expected result is like this:
<image:image>
<image:loc>https://example.com/not_under_wp/img.png</image:loc>
</image:image>
Possible Fix
You need to be aware of the path of home_url in absolutize_url()
// for /resource type urls.
$home_url = untrailingslashit( home_url() );
$home_path = wp_parse_url( $home_url, PHP_URL_PATH );
if ( $home_path ) {
$home_url = preg_replace( "#{$home_path}$#", '', $home_url );
}
$url = $home_url . $url;
Version Info (please complete the following information):
- WordPress version: 5.4.2
- All in One SEO Pack version: 3.5.2
- PHP version: 7.0.33
@chrome-cgi Thank you for reporting this. I've verified the problem, however, your code snippet didn't work for me. We'll take a look and implement improvements to how we handle sites where WordPress is installed in its own directory.
@chrome-cgi I tried reproducing the issue using these steps (first method) and the image path was correct - https://wordpress.org/support/article/giving-wordpress-its-own-directory.
Is your site configured using that method? If so, please note that you shouldn't rename your site URL/home URL in that case. Feel free to let us know if you set up your site in a different way, but for now I'm going to close the issue.