If you’re looking for a way to create a WordPress HTML sitemap without installing any plugins, this guide is for you. Follow along with the video below…
Watch This:
Code For Template File
/** * The template for displaying the sitemap page * Template Name: Sitemap * * @link https://codex.wordpress.org/Template_Hierarchy * */
Code For Sitemap
<h2 id="sitemap-pages">Pages</h2> <ul> <?php wp_list_pages( array( 'exclude' => '1387', 'title_li' => '', ) ); ?> </ul> <h2 id="sitemap-posts">Posts</h2> <ul> <?php $postsArgs = array( 'post_type' => 'post', 'posts_per_page'=>'-1', // 'post__not_in' => array(), ); $postsLoop = new WP_Query( $postsArgs ); while ( $postsLoop->have_posts() ) { $postsLoop->the_post(); ?> <li <?php post_class(); ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } wp_reset_query(); ?> </ul> <h2 id="sitemap-posts-categories">Post Categories</h2> <ul> <?php wp_list_categories( array( 'title_li' => '', 'show_count' => false, // 'exclude' => array(), ) ); ?> </ul> <h2 id="sitemap-posts-tags">Post Tags</h2> <?php $tags = get_tags(array( // 'exclude' => '', ) ); if ($tags) { ?> <ul> <?php foreach ($tags as $tag) { ?> <li class="tag-id-<?php echo $tag->term_id ?>"><a href="<?php echo get_tag_link( $tag->term_id );?>"><?php echo $tag->name ?></a></li> <?php } ?> </ul> <? } ?> <h2 id="sitemap-our-work">Our Work</h2> <ul> <?php $postsArgs = array( 'post_type' => 'our-work', 'posts_per_page'=>'-1', //'post__not_in' => array(), ); $postsLoop = new WP_Query( $postsArgs ); while ( $postsLoop->have_posts() ) { $postsLoop->the_post(); ?> <li <?php post_class(); ?>><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } wp_reset_query(); ?> </ul>
Need Help With Your WordPress SEO?
If you need help ranking your WordPress website in Google, get in touch with our WordPress SEO Company today for a FREE, no obligation quote!