How to include or exclude pages from header menu navigation bar in Wordpress
So, how to customize WordPress header navbar:
Adding too many pages to a WordPress blog that has a navigation bar in the header can really make your Wordpress blog a mess. There are options to control what pages are shown in the navigation bar and even a way to add external links.
Ok, open folder where WordPress installed: wp-content/themes/YourThemeName/ and open header.php. And find this code:
A little added code can either include or exclude any page or pages but the first thing to do is find the page numbers of the pages you want to include or exclude. Log in to the admin, usually it place: http://www.YouSiteName.com/wp-admin/. Click on Pages -> Edit page. And look at the URL: 43 is Your page ID
The code to add to the header.php file to include only pages 43 and page 44 will look like the examples below. You can add as many page numbers as you want in a comma separated list, or just one.
Look closely at the difference between the first example and the added code in the second. The code added was this &exclude=43,44 with no extra spaces and keeping the ' at the end.
To exclude certain pages from appearing in the navigation bar simply use exclude instead in include in the code. The example below will not show pages 43 and 44:
Now what about sorting the order the pages are shown? Well there are options that you can use and these are found on the WordPress codex. But if none of those options work for you you could use the includes code multiple times to set the order on your own. For example this would show page number 43 first then page 1 second:
Did you notice the code for the Home link in the first code example? I bet you are thinking now right? Yes that is the code we can learn from to hard-code external links. This part is very simple just place the code for the external link anywhere within the navigation bar you want the link to appear. In the sample below the Home link is first, page number 43 second, an external hard-coded link and last is page number 1.
I was precisely looking for how to add external links to the top menu. This code is really useful and I hope you will be providing much more information in Future. Now with the WordPress 3.0 launch this thing will get easier. You can create a menu directly from the admin side.
'm using your plugin and it works great. Im trying to incorporate a wordpress store plugin, but when i do it creates extra pages in the header. Now, i realize that is the problem of the other plugin not yours, but is there a way to make pages that do not display in the nav bar. i think that would help things out a bit.
Comments
Quote:
I double cross checked not to have left the brackets opened
I had copied the ending bracket twice