Sure. With the code I added here we can change the URL of the sitemap links from the WordPress URL to the Frontity URL. For example, a link that is https://wp.domain.com/post-1 will become https://www.domain.com/post-1.
Then, the only thing we would need to do is to add the sitemap URL (https://wp.domain.com/sitemap.xml) to the robots.txt file of the Frontity site:
Itās not the only way to add sitemap support though, there are more ways. For example, we could add a Frontity package that requests the sitemap from the WordPress site and filters the URLs before returning it.
This is a very simplified version, but something like this:
My site does not have a sitemap yet. I use Yoast seo, but could not find a solution to make it work with Frontity. I tried to use this, but without succes.
I tried your solution, but I get **Fatal error** : Uncaught Error: Call to undefined function unparse_url.
Can you share that function? Or do you have a good solution with Yoast Seo?
It should be fairly easy to do because itās simply replicating what we have for the favicon.ico file, but with a robots.txt file. If itās not present, it should return the default robots.txt file we have defined now.
is it possible to do something to write the original domain in robots.txt, not a subdomain?
For example, for nodejs to take the content at wp.domain.com/sitemap.xml, and give it to the address domain.com/sitemap.xml
This is about to be released in the upcoming WordPress 5.5
@santosguillamot, now that our plugin is going to know if Frontity is being used in decoupled mode and the Frontity URL, it could add the filters for core sitemaps. Maybe also filters for other popular plugins, like Yoast.
EDIT: By the way, I donāt know if the filter I proposed in the opening post is still valid.
Iāve been taking a look at it and it seems the filters you suggested in the opening post arenāt available anymore. We can find the new filters in the announcement or the plugin description.
I thought wp_sitemaps_posts_pre_url_list could work similar to the ones you used, but after doing some tests I think the purpose is different and you donāt have the $url_list at that point (youāll have to generate it yourself).
Not sure but maybe we could use the filter wp_sitemaps_posts_entry, but I havenāt tested it yet. Iāll try to do it and keep you posted.
Iāve been taking a deeper look at that filters and I think itās what we should use. Iāve tested them locally and it worked great. The logic is almost the same as the one Luis shared in the opening post, I just had to adapt it to these filters and I had to define the unparse_url() function. With this we can use the Sitemaps functionality and change the url to point to the Frontity domain. This is the code I was using:
Thank you very much for providing this example.
Have some questions on that:
I use a lot of custom taxonomies. Do you think i have to add_filter for all the sitemaps? See Screenshot
As you can see from the screenshot the sitemap on my side is generated by Yoast, but i also use WordPress 5.5.1 version. So do you think i have to use them as you described here?
If youāre using Yoast, I think the same filter should work for all the Post Types and for any url. And if you are using Yoast sitemap you should use this filter I mentioned. I think Yoast is overriding default WordPress sitemap so it shouldnāt be a problem.
This is not part of Frontity, itās part of your backend. You just have to specify in your robots.txt where your sitemap, adding a line like this one:
As you mentioned, it works well just changing to the yoast filter instead: add_filter('wpseo_sitemap_entry', 'change_urls');
What it does miss though is the front page url and the archive pages for custom post types.
Adding a page for the CPT archive would include it in āpage-sitemap.xmlā though. Which can be a temporary solution. We would still be able to use the url as archive, if thatās preferred.