Header Ads

Breaking News
recent

How to create an HTML sitemap in wordpress 2016

Sitemap is the one of the thing that we need to submit to Search Engine.HTML sitemap makes it easier for users as well as Search Engine Bot to find content on your site.There are many plugins to create HTML sitemaps in WordPress. But I will suggest you to create your HTML Sitemap Manually, You can do it with a bit of php code, you can create an HTML sitemap in WordPress yourself and have more control over the output So that you will got more places in Search Engine Results.Let see below that how to create it:


How to create a HTML sitemap in wordpress:

Follow the given steps to create a sitemap:
1. First log in to your hosting account where you have installed your wordpress.
2. Open the File Manager and find function.php in your directory.
3. Open function.php  for editing.
4. Paste the below given code just after <?php tag.




function spp_html_sitemap() {
$spp_sitemap = '';
$published_posts = wp_count_posts('post');
$spp_sitemap .= '<h4 id="sitemap-posts-h4">Here is a list of of my '.$published_posts->publish.' published posts</h4>';
$args = array(
'exclude' => '', /* ID of categories to be excluded, separated by comma */
'post_type' => 'post',
'post_status' => 'publish'
);
$cats = get_categories($args);
foreach ($cats as $cat) :
$spp_sitemap .= '<div>';
$spp_sitemap .= '<h3>Category: <a href="'.get_category_link( $cat->term_id ).'">'.$cat->cat_name.'</a></h3>';
$spp_sitemap .= '<ul>';
query_posts('posts_per_page=-1&cat='.$cat->cat_ID);
while(have_posts()) {
the_post();
$category = get_the_category();
/* Only display a post link once, even if it's in multiple categories */
if ($category[0]->cat_ID == $cat->cat_ID) {
$spp_sitemap .= '<li class="cat-list"><a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a></li>';
}
}
$spp_sitemap .= '</ul>';
$spp_sitemap .= '</div>';
endforeach;
$pages_args = array(
'exclude' => '', /* ID of pages to be excluded, separated by comma */
'post_type' => 'page',
'post_status' => 'publish'
);
$spp_sitemap .= '<h3>Pages</h3>';
$spp_sitemap .= '<ul>';
$pages = get_pages($pages_args);
foreach ( $pages as $page ) :
$spp_sitemap .= '<li class="pages-list"><a href="'.get_page_link( $page->ID ).'" rel="bookmark">'.$page->post_title.'</a></li>';
endforeach;
$spp_sitemap .= '<ul>';
return $spp_sitemap;
}
add_shortcode( 'spp-sitemap','spp_html_sitemap' );


The Above code will list all of your pages and posts into your sitemap and sort out all posts category wise. A single post  will be displayed once no matter if the post published under multiple categories.I hope you understand it.

How to remove pages from Wordpress sitemap:


If you want to remove pages from wordpress sitemap just remove the following given code from above given code:

$pages_args = array(
'exclude' => '', /* ID of pages to be excluded, separated by comma */
'post_type' => 'page',
'post_status' => 'publish'
);
$spp_sitemap .= '<h3>Pages</h3>';
$spp_sitemap .= '<ul>';
$pages = get_pages($pages_args);
foreach ( $pages as $page ) :
$spp_sitemap .= '<li class="pages-list"><a href="'.get_page_link( $page->ID ).'" rel="bookmark">'.$page->post_title.'</a></li>';
endforeach;
$spp_sitemap .= '<ul>';


You can also exclude certain pages and categories by entering their ID(mentioned in comments of above code).

I hope now you are able to make your own sitemap easily.If you like this article share it on social media to help other blogger brothers.
Let me know if you have any problem regarding to this article.If you have any problem you can comment me below.Thanks for reading this article.Stay tuned for more articles.

1 comment:


  1. Hello,

    we provide affordable and result-oriented SEO services, please give a chance to serve you.


    Thanks
    Admin: E07.net

    ReplyDelete

Powered by Blogger.