Simple Site Map Plugin
I created a site map plugin for Wordpress that simply lists all the pages you have on your site. It also comes with an optional category listing. You can edit the plugin to your liking. It was easy to create since it only has two main functions. The first function sitemap lists the pages using the wordpress generated tag wp_list_pages. I’ve also commented out a categories listing. You can add other listings if you’d like. The second major function generate_sitemap creates a shortcut you can use on any page you create when you go to Write –>Page. All you need to do is insert <– sitemap –> anywhere on that page and hit Publish.
Copy and paste the code below into a text editor such as notepad, and save it as sitemap.php. Then upload it to your site’s plugins folder. Activate the plugin in the Dashboard and create your site map page. To see a working site map, click here. If you have any questions, feel free to ask.
<?php
/*
Plugin Name: Site Map
Plugin Author: Sue
Plugin Description: Generates a site map based on pages but is customizable via plugin editor. You can get to that by clicking on the title of this plugin. Use &lt;!&ndash;&ndash; sitemap &ndash;&ndash;&gt; on any page in code view to display the site map.
Plugin Author URI: http://endless-sonata.net
Plugin URI: /wp-admin/plugin-editor.php?file=sitemap.php
*/
function sitemap() {
echo "<ul>";
wp_list_pages('title_li=');
echo "</ul>";
/*
// optional list categories
echo "<ul>";
wp_list_categories('title_li=');
echo "</ul>";
// you may add any other list options you'd like
*/
}
function generate_sitemap($content) {
if (strpos($content, "<!-- sitemap -->") !== FALSE) {
$content = preg_replace('/<p>\s*<!--(.*)-->\s*<\/p>/i', "<!--$1-->", $content);
$content = str_replace('<!-- sitemap -->', sitemap(), $content);
}
return $content;
}
add_filter('the_content', 'generate_sitemap');
?>
Similar Posts
6 Comments
Thank you for taking the time to leave a message. Your comment is much appreciated. Also, please leave a comment relevant to the posted topic. If this is your first time commenting, your comment will be held for moderation before being displayed. If you would like a custom avatar to appear beside your message, please sign up for an account on Gravatar

It’s great to see you helping out and coding for others :). I suck at coding myself haha :P!
Ooh, interesting! I’ve always wanted to learn PHP, and did manage to understand a bit while converting my layouts to WP. Hopefully I’ll get more time to figure it out after I graduate!
That’s great! Now all my pages don’t have to be listed on my index!
Oh, looks really interesting. My blog is not complex enough to require a site map yet; but if it ever does one day, I’ll remember to try yours out.
Did I ever mention how much you rock? Because you do
wow.. you made that script? cool! I’m using one now.
The one made by Dominic Foster.
Take Care!
-xoxo-