How to Add an HTML Sitemap Page in WordPress (2 Ways)

Understanding HTML Sitemaps in WordPress
An HTML sitemap is a dedicated page on your WordPress website that lists all of your site’s pages and posts in an organized and easily navigable format. Unlike XML sitemaps, which are designed for search engines, HTML sitemaps are primarily for human visitors. They provide a clear overview of your website’s content, making it easier for users to find what they’re looking for.
While search engines like Google can crawl your site effectively with or without an HTML sitemap, users benefit significantly from having a visual representation of your site’s structure. This is particularly useful for websites with a large number of pages and posts, complex navigation, or content that might not be easily discoverable through standard menus and search functions.
Here’s why you should consider adding an HTML sitemap:
- Improved User Experience: A well-structured sitemap helps visitors quickly locate specific content, enhancing their overall experience on your site.
- Enhanced Navigation: It acts as a supplementary navigation tool, providing an alternative way to explore your website’s content.
- Increased Pageviews: By making it easier for users to find more content, an HTML sitemap can encourage them to explore more pages on your website.
- Better Internal Linking: An HTML sitemap naturally creates internal links between your pages and posts, which can improve your site’s search engine optimization (SEO).
Method 1: Using a WordPress Sitemap Plugin
The easiest and most common way to add an HTML sitemap to your WordPress website is by using a plugin. Numerous plugins are available that can automatically generate a sitemap page based on your existing content. Here’s a step-by-step guide using a popular plugin:
- Choose a Sitemap Plugin: There are several excellent WordPress sitemap plugins available. Some popular options include:
- Simple Sitemap
- WP Sitemap Page
- All in One SEO (includes a sitemap generator)
- Install and Activate the Plugin:
- Navigate to your WordPress dashboard.
- Go to “Plugins” > “Add New.”
- Search for “Simple Sitemap.”
- Click “Install Now” next to the plugin.
- Once installed, click “Activate.”
- Configure the Plugin (if necessary): Many sitemap plugins, including Simple Sitemap, work right out of the box. However, you may want to customize certain settings.
- Go to “Settings” > “Simple Sitemap” (or the corresponding settings page for your chosen plugin).
- Review the available options. Common settings might include:
- Excluding specific pages or post types from the sitemap.
- Changing the order of pages and posts.
- Adjusting the display style.
- Make any desired changes and save your settings.
- Create a Sitemap Page: You need to create a new WordPress page where the sitemap will be displayed.
- Go to “Pages” > “Add New.”
- Give your page a title (e.g., “Sitemap”).
- In the content area, insert the sitemap shortcode. The shortcode for Simple Sitemap is `[simple-sitemap]`. Consult the documentation for your chosen plugin for the correct shortcode.
- Publish the page.
- Verify the Sitemap: Visit the newly created sitemap page on your website. You should see a list of all your pages and posts, organized in a clear and navigable format. If you made any configuration changes in step 3, confirm that they are reflected in the sitemap display.
For this example, we will use the “Simple Sitemap” plugin. The steps are generally similar for other plugins, although the settings interfaces may vary.
This method provides a quick and easy way to generate a fully functional HTML sitemap without requiring any coding knowledge. The plugin handles the complexities of retrieving and displaying your website’s content.
Method 2: Manually Creating an HTML Sitemap
While using a plugin is generally the preferred approach, you can also manually create an HTML sitemap. This method requires some coding knowledge but offers more control over the sitemap’s design and functionality.
- Create a New WordPress Page: As with the plugin method, the first step is to create a new WordPress page that will house your sitemap.
- Go to “Pages” > “Add New” in your WordPress dashboard.
- Give your page a title (e.g., “Sitemap”).
- Leave the content area blank for now.
- Publish the page.
- Edit the Page Template: You’ll need to modify the page template to include the code that generates the sitemap. The easiest way to do this is to create a custom page template.
- Locate your theme’s `page.php` file (or a similar page template file). This is usually found in the `/wp-content/themes/your-theme-name/` directory. If you’re using a child theme, make sure to modify the file in your child theme’s directory to avoid losing your changes when the parent theme is updated.
- Create a copy of `page.php` and rename it something descriptive, like `sitemap-template.php`.
- Open `sitemap-template.php` in a text editor.
- Add the following code at the very beginning of the file to define this as a custom page template:
“`php
“`Replace “Sitemap Template” with the desired name for the template in the WordPress page editor.
- Now, add the code to generate the sitemap within the main content area of the template. This code will retrieve all pages and posts and display them as a list. Paste the following code *after* the line containing `get_header();` and *before* the `get_sidebar();` line (if your theme has a sidebar):
“`php
Pages
-
‘menu_order’, ‘sort_order’ => ‘asc’));
- ‘ . esc_html($page_title) . ‘
foreach ($pages as $page) {
$page_link = get_permalink($page->ID);
$page_title = $page->post_title;
echo ‘‘;
}
?>Posts
-
-1,
- ‘ . esc_html($post_title) . ‘
‘orderby’ => ‘date’,
‘order’ => ‘DESC’,
‘post_type’ => ‘post’,
‘post_status’ => ‘publish’
);
$posts = get_posts( $args );
foreach ($posts as $post) {
$post_link = get_permalink($post->ID);
$post_title = $post->post_title;
echo ‘‘;
}
?>
“` - Save the `sitemap-template.php` file.
- Assign the Template to Your Sitemap Page:
- Go back to your WordPress dashboard and navigate to “Pages” > “All Pages.”
- Find the sitemap page you created earlier and click “Edit.”
- In the “Page Attributes” meta box (usually located on the right-hand side of the screen), find the “Template” dropdown menu.
- Select the “Sitemap Template” (or whatever you named your custom template) from the dropdown.
- Click “Update” to save the changes.
- Add Styling (Optional): The basic sitemap generated by the code above might not be visually appealing. You can add CSS styles to improve its appearance.
- Open your theme’s `style.css` file (or a custom CSS file).
- Add CSS rules to style the `sitemap-container`, `h2`, and `ul` elements. For example:
“`css
.sitemap-container {
margin-bottom: 20px;
}.sitemap-container h2 {
font-size: 20px;
margin-bottom: 10px;
}.sitemap-container ul {
list-style: none;
padding: 0;
}.sitemap-container li {
margin-bottom: 5px;
}
“`Adjust the styles to match your website’s design.
- Verify the Sitemap: Visit the sitemap page on your website. You should now see a list of your pages and posts, styled according to your CSS.
This method provides a more customized HTML sitemap. You have complete control over the code and can modify it to suit your specific needs. However, it requires a basic understanding of HTML, CSS, and PHP.
Considerations for Both Methods
Regardless of which method you choose, keep the following points in mind:
- Keep it Updated: An HTML sitemap is only useful if it accurately reflects your website’s content. Whether using a plugin or manual code, ensure it dynamically updates whenever you add or remove pages or posts. Most plugins automatically handle this, but with the manual method, the code always reflects the latest data.
- Structure and Organization: Organize your sitemap logically. Consider grouping pages and posts by category or topic. For larger websites, you might want to use subcategories or multiple sitemap pages.
- Accessibility: Ensure your sitemap is accessible to all users, including those with disabilities. Use clear and concise language, and provide alternative text for any images.
- Mobile-Friendliness: Make sure your sitemap is responsive and looks good on all devices, including smartphones and tablets. Test it on different screen sizes to ensure a good user experience.
- Avoid Duplicate Content: Ensure that the content on your sitemap page isn’t duplicated elsewhere on your website. Use `rel=”canonical”` tags if necessary to avoid any potential SEO issues.
By following these steps and considerations, you can effectively add an HTML sitemap to your WordPress website, improving user experience and enhancing navigation. Choose the method that best suits your technical skills and website needs. If you are not comfortable editing code, a plugin offers a straightforward solution. If you require more control and customization, the manual method is a viable option.
- How to Add Title and NoFollow to Insert Link Popup in WordPress
- 13 Ways to Create a Mobile Friendly-WordPress Site (Expert Tips)
- How to Easily Disable the Default WordPress Sitemap
- How to Easily Create a Multilingual Sitemap in WordPress
- How to Do an SEO Competitor Analysis in WordPress (2 Easy Ways)
- How to Switch From Blogger to WordPress Without Losing Google Rankings
- How to Remove Parent Slug From Child Page URL in WordPress