Generate custom XML sitemap on post save in WordPress

It’s not pretty, but it works. The script generates a custom XML sitemap on post save in WordPress. It’s looping through every page for every post with the post type “city” (since it’s unique content based on what city you choose). Remember to also use the URL parameter tool in Google Search Console to make the crawlers index the pages correctly. Since we use Polylang, the script will create a sitemap for each language.

Don’t forget to create the folder “sitemaps” in your theme folder and make it writable.

 

Leave a Comment