awesomemotive / all-in-one-seo-pack

All in One SEO plugin for WordPress SEO
https://aioseo.com
339 stars 155 forks source link

XML Sitemap - Wrong image URL in post-sitemap.xml #3175

Closed chrome-cgi closed 4 years ago

chrome-cgi commented 4 years ago

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):

wpsmort commented 4 years ago

@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.

arnaudbroes commented 4 years ago

@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.