Hello,
Thank you for contacting Rank Math today.
We really appreciate the suggestion. I have forwarded this to the dev. team and we will see about the best method to handle this and incorporate it in a future update.
For now, you can use the following filter code to remove the trailing slash from the Posts URL:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
if ( 'post' === $type ) {
$url['loc'] = untrailingslashit( $url['loc'] );
}
return $url;
}, 10, 3 );
I hope that helps.
Hi Pratik,
I tried your suggestion, and that does not work either.
We need to remove the trailing slashes for a few CPT’s and not all links, it appears that for the filter you suggested the $type is hardcoded as ‘post’ so it pretty much affects every link output in the sitemap if that filter is used.
class-post-type.php
line 208
$url = $this->do_filter( ‘sitemap/entry’, $url, ‘post’, $post );
Thank you and happy holidays.
Hello
Thank you for contacting us again and sorry for the delay.
For now, our filter hooks can’t get a specific post type but like my colleague, we will forward this to the dev team so we can incorporate this in a future update.
But we think we might another solution for you. Here you can use this code. This code tested in our end.
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){
// This code will get the current xml url
$get_current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$current_url = 'https://www.drugstrategies.org/treatment-center-sitemap1.xml';
// This section will determine if the current xml url is equal to the current_url variable
if ( $get_current_url === $current_url ) {
$url['loc'] = untrailingslashit( $url['loc'] );
}
return $url;
}, 10, 3 );
Make sure you disable your XML cache after you put the code above or if you got any cache plugin clear it so you will see the changes on XML.
You can disable the Rank Math XML cache by adding this to your functions too.
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
You can delete the Rank Math cache filter after you see the changes and you satisfy with the result.
Hope this solves your issue.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.