I like to hardcode everything on my WordPress websites, without using any plugins. Is there any way to generate or update my sitemap everytime I publish/update a post on one of my Multisite blogs, without using plugins?
Leave a Reply
You must be logged in to post a comment.
The following code works right off the bat. Your sitemap will show up on:
https://your-website-name.com/sitemap.xml
Every time you create or update a page, post or custom post type it will show. Make sure to add the name of your custom post type:
Before using the code provided in w3uiguru’s answer, I had to make some improvements that follow the accepted standard for XML files. The code is below:
I don’t know whether this works on multisite, but it is working perfect in a single WordPress installation for me.
When you create/update any posts, or pages, it will generate a sitemap.xml file and update the links (URLs) with the most recent first (last modified).
Copy and paste the below code in your active theme’s functions.php file:
I changed the code from @locutor-antonio-cezar a little bit as I was looking for a very specific use case. I needed a sitemap specially written for Google News. What is different? The whole markup follows the rules. In my specific case, I limited the number of posts to 20. Also posts older than 2 days disappear. Maybe somebody needs this: