Home Blog Generate a Hierarchical Sitemap of WordPress Pages with Shortcode

Generate a Hierarchical Sitemap of WordPress Pages with Shortcode


WordPress pages, unlike posts, are arranged in a child-parent hierarchical relationship. This relationship makes grouping content under a single umbrella a key feature of WordPress. Not totally unlike the shortcode we’ve previously provided that would render child pages of a parent page, this function, utilizing WordPress’ wp_list_pages() function, will display a hierarchical sitemap of all pages on your website, or those that share a parent page.

We considered and quickly moved on from this function when considering how to render our platform help pages. That said, it may still come in useful.

The Result

Printing out all the pages on our site is achieved with the shortcode of [bmsitemap].

■ ■ ■

  1. About Us
  2. Services
  3. Contact
  4. Search Engine Optimization
  5. Privacy and Terms
  6. BeliefMedia Home Page
  7. Belief Marketing Podcast
  8. Reference
  9. Telephone Consultation
  10. Aviation Media Management
  11. Code Reference
  12. Example Pages
  13. Frequency Asked Questions
  14. Landing Pages
  15. Locations
  16. Digital Marketing
  17. Social Media Management
  18. Tools
  19. Legacy Features
  20. Charity
  21. Mortgage Broker Growth Program
  22. Web Design
  23. Address Book
  24. Martin Khoury
  25. Make an Appointment
  26. Making an API Request

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin. You may optionally download and install our plugin from the bottom of of the page.

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

An alternate method of printing the map (and that which is documented) would be passing the arguments in an array (the function uses wp_parse_args() to merge the $args with the $defaults values). In fact, we could do away with the virtually every statement after the $atts array, and pass the $atts array directly to the wp_list_pages() function.

Most of the shortcode attributes are detailed on the WordPress Codex page . Those that aren’t are parent (the parent page of the list) and list_style. The list styles are detailed on W3schools (and WP ).


  • If you want to create a custom list, consider create a custom walker class to extend wp_list_pages() (inheriting the properties of the Walker_Page class). Usage of an extended class essentially means you can modify the list in virtually any way.


Title: Sitemap of WordPress Pages with Shortcode
Description: Generate a Hierarchical Sitemap of WordPress Pages with Shortcode.
Download: Shortcode (V0.2) | WP Plugin (V0.2) | Plugin Page

■ ■ ■

Interested in WordPress and Web Design? Subscribe to our list and we'll send you subscriber-only tools and plugins

Short URL for this post: http://shor.tt/Jnh


Please enter your comment!
Please enter your name here