How to Display Selected WordPress Pages in Navigation Bar

If your blog has a navigation bar in or near the header and you create a lot of pages on your WordPress blog chances are it is getting somewhat cluttered. You can control what pages are displayed by including the ones you want or excluding a certain few. Here is a short WordPress guide to help you clean things up.

Warning before editing any theme files make a backup so you can fix any mistakes!

The first thing to decide is if you are going to include certain pages or exclude certain pages. Each page has an ID number associated with it. To find the page’s ID numbers in the dashboard click Manage, Pages and look for the ID number of the page. Next open your header.php file and look for this code:

<?php wp_list_pages(‘depth=1&title_li=’); ?>

That bit of code is going to display all the pages you create. To exclude certain pages use the below code in its place and add the page ID numbers comma separated. The example below is excluding page ID 6 and 4.

<?php wp_list_pages(‘title_li=&depth=1&exclude=6,4′); ?>

To include only certain pages you can try this next bit of code:

<?php wp_list_pages(‘title_li=&depth=1&include=6,4′); ?>

There are many more parameters to list pages, learn more about WordPress page navigation here: WP List Pages

You can also ‘hard code’ any URL in the WordPress navigation bar as this previous post explains: Specify WordPress Navigation Page Links

Disclosure: Some of the links in this article are affiliate links and we may earn a small commission if you make a purchase, which helps us to keep delivering quality content to you. Here is our disclosure policy.

Editorial Staff
Editorial Staff
Editorial Staff at WPArena is a team of WordPress experts led by Jazib Zaman. Page maintained by Jazib Zaman.

LEAVE A REPLY

Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!

spot_img

Related Articles

Why WordPress Is The Best CMS? (And, Possible Alternatives)

Why WordPress is the best CMS? Having a website has become a necessity for both individuals and businesses. Content Management...
Read More
When optimizing the speed of your WordPress site, you might come across a performance metric known as Time to First...
Are you dealing with a broken WordPress site and don't know what to do? If your website is showing a...