How to create dynamic HTML sitemap in WordPress with a shortcode (and exclude post types)
An HTML sitemap is a simple way to display all your website’s content in one place. It helps visitors and search engines quickly navigate your site’s structure. In this tutorial, we’ll show you how to create a WordPress shortcode that generates an HTML sitemap displaying Pages , Posts , and Custom Post Types (CPTs) – with an option to exclude certain post types you don’t want to display. By the end, you’ll have a clean, dynamic sitemap you can insert anywhere using [html_sitemap exclude=”product,portfolio”] . Here’s an example: Pages - Home - About Us - Contact Blog Posts - How to Build a WordPress Site - Top 10 SEO Tips Products - Product A - Product B Add this code to your theme’s functions.php file or in a custom plugin: // [html_sitemap] shortcode with dynamic exclude option function generate_html_sitemap($atts) { // Parse shortcode attributes $atts = shortcode_atts(array( 'exclude' => '', // Default: no exclusions ), $atts, ...