-
Since you do not provide any doc at all on this, I was checking via error_log. Nothing ever appears in my log. What gives?
add_filter( ‘rank_math/sitemap/post_type_archive_link’, function( $archive_url, $post_type ){
error_log(“generate_post_type_archive_link – url: ” . $archive_url);
return $archive_url;
}, 10, 2 );add_filter( ‘rank_math/sitemap/entry’, function( $url, $type, $object ){
error_log(“generate_sitemap_url – url: ” . $url);
return $url;
}, 10, 3 );See a pic of my snippets here: https://snipboard.io/A7xmHW.jpg
-
Hello,
Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.
This code’s intended purpose is to change or remove an archive URL from the sitemap of the plugin. You can see this here: https://rankmath.com/kb/filters-hooks-api-developer/#6-filter-to-change-remove-archive-url-plugin-uses-in-th-xml-sitemap
The filter code you are using here seems like you want to generate an error log or something. Could you kindly clarify what you expect to achieve or your end result?
We really look forward to helping you.
Thank you.
I need to remove the archive from the sitemap. Archives will provide links to all posts – if there is a reason why some posts are not relevant to the site, beyond draft status, archives cannot be used.
I have a few pages that serve as my archives (at least from a ‘crawl’ perspective – these pages are critical.) If archives are needed for the sitemap, I would want to add these links (plural) instead of the archive. Perhaps I can add multiple pages in place of the archive?
I need to change part of the url. This would be needed by anyone that customizes their permalinks since your plugin does not use the permalinks for the links (I believe this is a bug since permalinks do not necessary reflect the type/slug.)
Hello,
Thank you for bringing this to our attention and apologies for the inconvenience caused.
Assuming you are using the latest version of all the plugins and the themes (please update if not yet), it would seem like a conflict with one of the plugins or the theme you are using.
To determine that, please follow this troubleshooting guide:
https://rankmath.com/kb/check-plugin-conflicts/Only the site admin would know and your users won’t be affected by this troubleshooting.
If the issue persists, please record a video screencast using a tool like Loom showing the troubleshooting and edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
Please do take a complete backup of your website before sharing the information with us.
We really look forward to helping you.
What are you talking about – THIS IS A DOCUMENTATION REQUEST!
Hello,
Thanks for getting back. Sorry for the delay and any inconvenience that might have been caused due to that.
I need to remove the archive from the sitemap. Archives will provide links to all posts – if there is a reason why some posts are not relevant to the site, beyond draft status, archives cannot be used.
You can simply set your archives to noindex from WP Dashboard > Rank Math > Titles & Meta. This will exclude your archives from the sitemap.
I need to change part of the url. This would be needed by anyone that customizes their permalinks since your plugin does not use the permalinks for the links (I believe this is a bug since permalinks do not necessary reflect the type/slug.)
Rank Math displays the same URL in the sitemap as you have set in your WordPress. If the URL of your page is type/slug then it will be displayed as the same in the sitemap. If it’s different in the sitemap then please share the URL of the page and login details to your wp-admin dashboard so we can look further into the issue.
Hope this helps. Let us know if you need any further assistance.
It seems you folks need an education about “permalinks”. There is lots of information on the internet about how permalinks can be customized to address the inadequacies of WordPress type/slug defaults. Here is one such page that, for example, introduces a tool to make the websites URL better reflect the content organization: https://permalinkmanager.pro/docs/tutorials/duplicate-permalinks-slug/
RankMath does not use permalinks but instead is hardcoded to use the type/slug approach. Normally that would be fine since you DO provide a filter. HOWEVER, you do not provide an example how to use the filter and my attempts have failed. I suggested that you provide actual code and doc of a working example FIRST, so that I know I am not wasting my time investigating plugin conflicts.
If you cannot accommodate this, just close this ticket. It will result in a low feedback score however, fyi.
Hello,
Thanks for getting back to us.
Here’s an example for the first filter that will change the product archive URL:
add_filter( 'rank_math/sitemap/post_type_archive_link', function( $archive_url, $post_type ){ if($post_type === 'product') { return 'https://google.com'; } return $archive_url; }, 10, 2 );And here’s the result on the
product-sitemap.xmlfile:
In your case since you mentioned multiple archives, you might need the other filter, using the entry sitemap.
To use that filter you need to do something like this:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){ if($object->ID === 'your_archive_link_id') { $url['loc'] = 'https://google.com' } return $url; }, 10, 3 );And if you want to fetch the ID of your links currently on the sitemap you can add a filter like this temporarily to print the ID:
add_filter( 'rank_math/sitemap/entry', function( $url, $type, $object ){ echo '<pre>'; print_r($object); echo '</pre>'; return $url; }, 10, 3 );Finally, in order to have this being updated constantly I would recommend that you completely disable any cache on your sitemap by also adding the following filter while working on this:
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');Hope this helps point you in the right direction to fix your sitemap links.
Don’t hesitate to get in touch if you require any further assistance.
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.
The ticket ‘I cannt get the filters to be triggered’ is closed to new replies.