---
title: "Simple WordPress Snippets to Improve Your Secondary Navigation"
id: "94921"
type: "post"
slug: "wordpress-snippets-secondary-navigation"
published_at: "2026-04-16T19:05:44+00:00"
modified_at: "2026-06-13T08:38:24+00:00"
url: "https://speckyboy.com/wordpress-snippets-secondary-navigation/"
markdown_url: "https://speckyboy.com/wordpress-snippets-secondary-navigation.md"
excerpt: "Using these WordPress snippets can further help users get where they need to go and discover content they may have otherwise missed."
taxonomy_category:
  - "WordPress"
  - "WordPress Designer"
taxonomy_post_tag:
  - "Code Snippet"
  - "Menu Design"
  - "Navigation"
---

# Simple WordPress Snippets to Improve Your Secondary Navigation

Last Update:  June 13, 2026  
 By  Eric Karkovack

[WordPress](https://speckyboy.com/category/wordpress/)
 / [WordPress Designer](https://speckyboy.com/category/wordpress/wordpress-designer/)

One of the great things about WordPress is the ability to reuse snippets of code over and over again within your themes. With that, you can build in ways to make websites easier to use.

In this article, we’re going to explore ways to improve secondary navigation. In other words, navigation that is *in addition* to your site’s main menu. Adding these extra elements can further help users get where they need to go and discover content they may have otherwise missed.

Here are four such snippets you can use in your WordPress themes. While they’ll work as-is, it’s a good idea to add your own custom styles to ensure a perfect fit with your site.

**Where to Place the Code Snippets:**The snippets below can be placed directly into your theme’s template files. The exact file may depend on your particular theme (check the [Template Hierarchy](https://wpshout.com/wordpress-template-hierarchy/)
 for ideas). And, to some degree, it’s a matter of personal preference. Use them where you think they’ll best serve your users.

It may also be a good idea to use [conditional statements](https://codex.wordpress.org/Conditional_Tags)
 so that snippets are only displayed when certain conditions are met. For example, you might not want a particular snippet to run on your site’s home page.

## 1. Easily Navigate Within a Section of Pages

```
<?php 
if (  $post->post_parent ) { 
    $children =  wp_list_pages( array( 
        'title_li' =>  '',
        'child_of' =>  $post->post_parent, 
        'echo'     => 0 
    )  ); 
} else { 
    $children =  wp_list_pages( array( 
        'title_li' =>  '', 
        'child_of' =>  $post->ID, 
        'echo'     => 0 
    )  );
} 
if (  $children ) : ?> 
    <ul> 
        <?php  echo $children; ?> 
    </ul> 
<?php endif; ?>
```

Source: [WordPress Code Reference](https://developer.wordpress.org/reference/functions/wp_list_pages/#comment-388)

This code makes for a great secondary navigation menu that could be used, for example, within a sidebar. It automatically displays the pages within the current section you’re browsing.

As an example, let’s say your site has an About Us page, with subpages for History, Mission Statement, and Staff. Users will be able to more easily navigate between the various pages within this section as a bulleted list of links.

## 2. Breadcrumb Style Page Titles

```
<h1  class="entry-title">
<?php
//  Conditional Statement to Check for a Parent Post
if($post->post_parent)  {
$parent_title = get_the_title($post->post_parent);
$parent_link = get_page_link($post->post_parent);
// Display Parent Post Link, Title and Separator
echo '<span  class="parent-title"><a target="_blank" href="' . $parent_link .  '">' . $parent_title . '</a></span>' . '&nbsp;<span  class="title-arrow">&#8250;</span>&nbsp; ';
}
// Display  the Current Page Title
the_title();
?>
</h1>
```

This snippet will check to see if the current page has a parent. If so, the parent page’s link and title are displayed within the `H1` tag at the top of the page. An arrow character is also displayed between the parent and current page title to complete the breadcrumb look.

Note that this breadcrumb effect only goes one level deep. So you’ll have to adjust the code if you want to link to multiple levels (Parent » Level 1 » Level 2).

## 3. JS Dropdown Menu of Tags

```
<?php
// Show a  Drop Down Menu of Tags
echo  "<select  onChange=\"document.location.href=this.options[this.selectedIndex].value;\">";
echo  "<option>Choose a Tag:</option>\n";
foreach (get_tags() as $tag) {
echo '<option value="' . get_tag_link($tag->term_id) .  '">' . $tag->name . '</option>\n';
}
echo  "</select>";
?>
```

If your site takes advantage of WordPress post tags, it may be useful to provide a simple way for users to navigate between them. This is particularly effective for sites with a lot of tags.

For example, a project I worked on used tags to filter posts by a relevant geographic region (of which there were dozens). This dropdown menu utilizes JavaScript to direct the user to whichever tag they choose instantly. You can also do something similar with [categories](https://developer.wordpress.org/reference/functions/wp_dropdown_categories/#comment-884)
.

## 4. Post Archive Pagination

```
<?php
the_posts_pagination(  array(
'mid_size' => 5, // The number of pages displayed in the menu.
'prev_text' => __( '&laquo; Go Back', 'textdomain' ), // Previous  Posts text.
'next_text' => __( 'Move Forward &raquo;', 'textdomain' ), // Next  Posts text.
) );
?>
```

Source: [WordPress Code Reference](https://developer.wordpress.org/reference/functions/the_posts_pagination/#comment-1516)

While many WordPress themes have a simple back and forth navigation for post archives, it’s a nice touch to add individual page numbers to the mix. It allows for navigating to a specific page and gives the user a sense of your content depth.

Note the `'mid_size'` argument in the code above. The number placed there will determine the number of pages seen between the Next and Previous text links.

## Give Users a Helping Hand

Each of the snippets above can bring some measure of organization to how users access your content. This is especially important on sites that have a lot of subpages or blog posts. In the case of subpages, primary navigation can become overwhelming if you try to display every subpage. Adding secondary navigation elements provide a more straightforward way for users to find what they’re looking for.

It’s also worth noting that these snippets are meant to be used as starting points. The flexibility of PHP and CSS allows you to add your own custom functionality and look. In many ways, you’re limited only by your own imagination.

## Related Articles

- [How to Create a Vertical Slide-Out Menu with CSS Transitions](https://speckyboy.com/vertical-slide-menu-css-transitions/) In this tutorial, we're going to create a vertical slide-out menu using CSS3 transitions. The menus will be place on the left-side of the screen…
- [How to Animate a CSS-Only Hamburger Menu and Icons](https://speckyboy.com/animating-css-only-hamburger-menu-icons/) Hamburger menu icons have become a staple in many websites and web apps, and whether you like them or not, they are becoming a familiar…
- [How to Create Responsive Off-Screen Menus with CSS3](https://speckyboy.com/off-screen-menus-transition-css3/) In this tutorial, we're going to create some slide and push menus using CSS3 transitions. The menus will be hidden off screen at first, and…
- [How to Create a Full Width Responsive Tiled Menu with CSS](https://speckyboy.com/full-width-responsive-tiled-menu/) Full width tiled menus are a crisp way for displaying your site's navigation and for giving end to end coverage, creating a very full-bodied effect…
- [8 CSS & JavaScript Snippets for Icon-Based Navigations](https://speckyboy.com/icon-based-navigation-css-javascript/) We share a collection of unique CSS and JavaScript code snippets that you can freely use to create icon-based website navigations.

## Related Topics

- [Code Snippet](https://speckyboy.com/topic/code-snippet/)
- [Menu Design](https://speckyboy.com/topic/menu-design/)
- [Navigation](https://speckyboy.com/topic/navigation/)

## Written by Eric Karkovack

Eric Karkovack is a web designer and WordPress expert with over two decades of experience. You can visit his business site [here](https://www.karks.com/)
. He recently started a writing service for WordPress products: [WP Product Writeup](https://wpproductwriteup.com/)
. He also has an opinion on just about every subject. You can follow his rants on Bluesky [@karks.com](https://bsky.app/profile/karks.com)
.

[Read more articles by Eric Karkovack](https://speckyboy.com/author/erickarkovack/)

---

Top

This page may contain affiliate links. At no extra cost to you, we may earn a commission from any purchase via the links on our site. You can [read our Disclosure Policy](https://speckyboy.com/affiliate-disclosure/)
 at any time.
