How to create sitemap in WordPress without plugin

HTML sitemap designed for Users, where user can easily view all links, pages category of the site. to create HTML sitemap for your WordPress website. follow below steps.

Step 1: Open functons.php file from theme

In First step you have to do is open your currently active theme from wp-content/theme folder. In that folder you will see many php pages. like header.php, footer.php, functions.php etc. So open functions.php file in your text editior.

step 2: Download below code and paste into functions.php

You can download source code from Github and paste into functions.php add_shortcode(‘sitemap’, ‘html_sitemap’); add_shortcode() is WordPress built-in function for shortcode tag. This function requires two parameter first your shortcode and second name of your php function during execution. you can use your shortcode on page or post like [your_shortcode_name].

Step 3: Add new page from wp-admin

Now in the last step we have to do is create new page form your wp-admin panel and Give appropriate name. In this tutorial am giving page name sitemap and paste shortcode [sitemaps] and save.

Now your site is ready with Dynamic HTML Sitemap. Whenever there is new page or post published, the link of that post/page will automatically listed in sitemap.

How to create XML Sitemap

XML Sitemap generally designed for search engines to crawling and indexing our web pages and to do that first we have to create XML sitemap and we have to submit our XML sitemap to Webmaster Tool. Follow below steps to create XML sitemap.

Step 1: Open functons.php file from theme

In first step again we have to open functions.php file in your text editor from your theme folder (wp-content/themes/your_theme_folder/functions.php).

Step 2: Download below code and paste into functions.php file

Just download and copy-paste code into your functions.php file.

add_action(“publish_post”, “XML_sitemap”); add_action(“publish_page”, “XML_sitemap”);

In downloaded file, you will see above 2 lines in that file. Here, add_action() hooks or call on a specific action. This function takes two parameter, first is the name of the action and second parameter is the name of function you wish to be hook.

For e.g : In above code we pass first parameter publish_post. So whenever you will publish your new post at that time WordPress will call a custom php function XML_sitemap which we passed as second parameter to hook.

Now new page or post published on your site, this code will clear older content and write new content in existing file. Check your sitemap by www.mydomain.com/sitemap.xml, you will see updated XML sitemap of your site.

WRITTEN BY

Rohit Gilbile



Leave a Reply