Hello,
Thank you for contacting Rank Math support.
We understand that you want to change the order of posts and pages in your sitemap HTML. Unfortunately, we don’t have a built-in option for that right now, but we have a workaround that you can try.
You can use this filter code to change the sort order of each post type in your sitemap HTML. Just copy and paste this code into your site. Learn how to add filters to your site here: https://rankmath.com/kb/wordpress-hooks-actions-filters/
Here’s the code you need to add:
add_filter( 'rank_math/sitemap/html_sitemap_post_types', function( $post_types ) {
$post_types[0] = 'page';
$post_types[1] = 'portfolio'; // Change this to your portfolio post type
$post_types[2] = 'post';
return $post_types;
} );
You can also add other post types to this code if you want to sort them differently. However, please note that this filter only works with post types and it won’t affect non-post type content, such as categories.
We hope this helps you achieve what you want. If you have any other questions or issues, please feel free to contact us again.
Thanks for the help, I will give that a go.
That was very helpful and exactly what I was looking for. Now if I want to order by menu order or some other way different to the 4 options in the HMTL sitemap settings, how would I achieve that also?
Hello,
We’re not sure we understand what you mean by “menu order”, can you please share more details on this so we can help?
Thank you for your patience and cooperation. Looking forward to hearing back from you.
Hi, sorry for the delay in responding.
I currently use Nested Pages to order my pages in the backend so the order reflects the menu order on the website. The only options to sort within Rank Math’s HTML Sitemaps are by published date, modified date, alphabetical and post ID. None of these options list the pages in the right order.
I would like to order them in the same order as how Nested Pages lists them. This adds an order value to the order field, so the homepage is order 1, the services page is order 2, and so on….
I would like the order of the pages on the HTML Sitemap page to be based on the order value. However, portfolios and posts can be ordered by published date as these display correctly.
Can you help here?
Hello,
Nested Pages is a third-party plugin and it is not possible for Rank Math to order the HTML sitemap based on the order of this plugin. In addition, the HTML sitemap will only nest your pages if they are actual subpages.
To get this to work, you would have to manually order this using the code we previously shared.
Best,
Sorry, I think I may have complicated things by mentioning Nested Pages.
Even without Nested Pages installed, the default WordPress pages have an ordered field under page attributes. I would like to order the pages within the HTML sitemap using this order value.
But as mentioned before, I would still like the posts and portfolio to be ordered using the published date.
How can I achieve this?
And will you soon make the HTML Sitemaps more customisable via the Rank Math settings?
Hello,
Unfortunately, right now, the sorting option you’re referring to is not possible in the HTML sitemap. You can only sort your pages by using the Sort By options available in the HTML Sitemap settings.
With that said, our developers are continuously working to improve those features of the plugin. If this is something we can include in the future, we will announce it on our communication channels and on the changelog page: https://rankmath.com/changelog/
Please don’t hesitate to let us know if you have any other questions.
Thank you.
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.