Create sitemap for wordpress
Today I am going to tell you how to make a user- and search engine friendly sitemap for wordpress that updates itself automatically whenever you add a post. First I have to explain a little about sitemaps. There are two types of sitemaps (at least):
- Sitemap.xml, this one you can submit to google for fastening your site’s indexing. This is ONLY for search engines, not for users. For this one there is a plugin that automatically creates the sitemap and submits it to Google everytime you update or write a post. The plugin is called google xml sitemap and can be downloaded from here. You only need to activate it, then it keeps your sitemap.xml up to date all the time.
- The sitemap page, this is just a page on your site where you list every single page that you have, like this one that I have on my site: The sitemap. This is good for users that wants an overview of your site, but also for search engines, because this works like an internal link-directory, this page contains a link to every page you have on your site. So even if a blogpost is two years old, there will be a link to it just one click away from the front page.
Building your sitemap for WordPress
We are going to concentrate on number two, because number one takes care of itself if you just install the plugin.
- Download Exec-php plugin. This plugin lets you run php-code in your posts. Do not worry if you don’t know php, I will tell you what to write. Activate that plugin.
- Download the WP_category_posts plugin. I have a modifyed (better) copy here (zip-file). Activate that plugin also.
- Create a new page on your WordPress blog. You can make a post also, but for this i suggest a page. Name it sitemap.
- Now we are going to use the two new plugins for making this page automatically show links to every page on the site. We will group the links by their categories. Create a heading for each category on the new page.
- Copy and paste this code under each heading: <ul><?php wp_cat_posts(9); ?></ul> . The number has to be changed to the ID of that category (9 is just an example).
- Open a new tab and go to admin panel –> posts –> categories, and check your category ID:s. Click on a category and you will see the ID in the adress field (example: ID=17). Make a list of the ID for every category.
- Go back to the sitemap page and put the right ID numbers in every place you have pasted the code <?php wp_cat_posts(9); ?>. This code will list all the posts in each category and output it as a link to that post.
- The sitemap is ready! Put a link to the sitemap in the footer, in the main menu, or in a widget, the important thing is that you can access the sitemap from the first page (or all pages) on your site. No matter how old your blogposts are, you will still find a link to them one click away from the front page!
Additional things you could do with the sitemap
If you have a lot of posts, you could consider to make the sitemaps for the different categories on different pages for keeping the sitemap page shorter.
If you have pages (about, contact, and so on) on your site, put a link to all of them also on your sitemap page.
If you make a new category, go to your category page and add that to your sitemap manually, include the code that pulls the ID, and that category will also be updated with posts.
Important! Do not edit the sitemap page through the “Edit”-button that some themes show under the content when you are logged in, this will make the php code unusable. Edit the sitemap page through the “admin panel –> pages” instead.