How to create sitemap in WordPress without plugin


How to create sitemap in WordPress without plugin

Since we know that plugin in WordPress is a considerable feature, it adds new features to your WordPress site. But you may get headache with excessive use of the plugin. It could slow down your website.

HTML sitemap for Users, where users can conveniently view all links, site category pages. To build your WordPress website HTML sitemap. Follow steps below.

Step 1: Open functons.php file from theme

Open your currently active theme from the wp-content/theme folder in the first move you have to do. You’ll see several pages of php in that tab. Like header.php, footer.php, the.php functions, etc. So open the functions.php file in your editor for text.

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 we need to build a new page in the last step for your wp-admin panel and give the correct name. In this tutorial I offer page name sitemap and paste and save shortcode [sitemaps].

With Dynamic HTML Sitemap now your site is ready. Whenever a new article or post is written, the link from that post / blog will be identified automatically in the sitemap.

How to create XML Sitemap

XML Sitemap usually designed for search engines to crawl and index our web pages and in order to do this we must first create XML sitemap and apply our XML sitemap to Webmaster Tool. To build XML sitemap, follow steps below.

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 example: In the code above we move the publish_post parameter first. So once you publish your new post at that time WordPress will call a custom XML_sitemap php function that we passed to hook as a second parameter.

Now published on your site as a new page or article, this code will clear out older content and write new content into existing file. Check your sitemap through www.mydomain.com/sitemap.xml, you’ll see your site’s modified XML sitemap.

Thanks You!

Menu