Interfacelab / ilab-media-tools

https://mediacloud.press/
GNU General Public License v3.0
114 stars 37 forks source link

Image URL is encoded when used with Yoast SEO sitemaps #214

Open timbolimboslice opened 1 year ago

timbolimboslice commented 1 year ago

Describe the bug This is a continuation of the bug that was posted here. I'm using this plugin along with Yoast SEO and having issues with the image URLs when generating sitemaps. I can also kick this issue back to the Yoast team if that makes more sense. Tagging @jawngee since he was on that original issue.

Example entry in a sitemap:

<url>
      <loc>https://www.texasmonthly.dev/travel/where-to-stay-eat-retreat-east-texas/</loc>
      <lastmod>2023-04-13T17:44:33+00:00</lastmod>
      <image:image>
             <image:loc>https%3A%2F%2Fimg.texasmonthly.com%2F2021%2F06%2Ftyler-east-texas-guide-caddo-lake.jpg%3Fauto%3Dcompress%26crop%3Dfaces%26fit%3Dfit%26fm%3Dpjpg%26ixlib%3Dphp-3.3.1%26q%3D45</image:loc>
      </image:image>
</url>

I was able to work around this issue with the following code, but I think a solve within the plugin itself would be better long term.

add_filter( 'clean_url', array( $this, 'fix_sitemap_image_urls' ), 1001, 1 );

public function fix_sitemap_image_urls( $url ) {
    if ( strpos( $url, 'img.texasmonthly.com' ) !== false && strpos( $_SERVER['REQUEST_URI'], '.xml' ) !== false ) {
          return htmlspecialchars( urldecode( $url ) );
    }

    return $url;
}

To Reproduce

Expected behavior Image URLs used in Yoast SEO sitemaps should work without adding custom code.

How did you install the plugin? via wordpress.org.

Additional context Media Cloud (Premium) - version 4.5.20 Yoast SEO Premium - version 20.3 WordPress Core - version 6.1.1

Let me know if theres any I can do to assist. Thanks!