Simple Sitemap in WordPress Without Plugin

As a webmaster, you ought to skills important a sitemap are often for your WordPress site. If you would like to be found easier and obtain more organic traffic, you ought to create a WordPress sitemap. If you would like to reduce the bound rate of your WordPress site, you need to also make a WordPress sitemap, so your site visitors can easily find the content they’re checking out in your site.

sitemap are often for your WordPress site

Your visitors also can make use of HTML sitemap to browse through your site and find the posts, pages or articles on your site easier. HTML sitemap makes it simpler for both clients and program to discover content on your WordPress blog and site.

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

Step 1: Open functons.php file from theme

Go to WordPress Website Appearance → Theme Editor → functions.php

Copy code and paste it at last line.

Open functons.php file from theme
// XML Sitemap__
add_action( 'publish_post', 'itsg_create_sitemap' );
add_action( 'publish_page', 'itsg_create_sitemap' );
function itsg_create_sitemap() {
$postsForSitemap = get_posts(array(
'numberposts' => -1,
'orderby' => 'modified',
'post_type'  => array( 'post', 'page' ),
'order'    => 'DESC'
));
$sitemap = '<?xml version="1.0" encoding="UTF-8"?>';
$sitemap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach( $postsForSitemap as $post ) {
setup_postdata( $post );
$postdate = explode( " ", $post->post_modified );
$sitemap .= '<url>'.
'<loc>' . get_permalink( $post->ID ) . '</loc>' .
'<lastmod>' . $postdate[0] . '</lastmod>' .
'<changefreq>daily</changefreq>' .
'</url>';
}
$sitemap .= '</urlset>';
$fp = fopen( ABSPATH . 'sitemap.xml', 'w' );
fwrite( $fp, $sitemap );
fclose( $fp );
}

Step 2: Add new page from wp-admin

Go to admin panel left side menu → Pages → Add New

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 save.

Whenever there is new page create name sitemap published, the link of that page will automatically listed in sitemap.

Add new page from wp-admin

Step 3: Sitemap.xml successfully created

Go to → http://localhost/wp/sitemap.xml 

OR: (https://www.yourdomain/sitemap.xml)

Hope you find this article useful. If so, please share on social media. Also if you have something to add to the code I provided code HTML sitemap in WordPress tutorial without plugin, please do comment below.

Other Popular Articles...

Leave a Comment