How To Hide A Page Or Category Link In WordPress

When it comes to customizing a WordPress theme to your liking you are provided with various different options. If one of those things requires excluding a page or category link from showing in your navigation you have come to the right place. One of the reasons may be that you have a thank you page setup and is only meant to be seen after a visitor subscribes to your newsletter or various other situations can call for hiding a page/category link.

In order to get started we need to find which file the code for the navigation that you are wanting to customize is located. With most WordPress themes, a horizontal navigation bar located near or at the top of the page will be placed in the header.php file. Otherwise you will most likely be editing a file called sidebar.php, of course depending on your theme it may be entirely different.

Finding the category IDs

Before we get into the actual code and editing it, I want to recommend that you first determine the page or category id(s) that you are wanting to exclude from showing in a list. We are going to need the id(s) to add into the code so having them ready beforehand can make this go a little bit quicker. To determine the id of the page or category you need to get the list of your pages/categories. If you are using WordPress 2.7, the categories list can be found under the Posts section and the pages under the Pages section.

Once you can see the list of your pages/categories all that you have to do to find the id is to mouse over the title of each one and look in the status bar of your web browser. If you are looking at your categories you should see a number listed after &cat_ID= in the status bar. This number is the id of the category that you are currently hovering over. A page’s id is slightly different and will be shown after &post= in the status bar.

Now that you know how to find the category and page ids, make a note of which ones you want to exclude from showing.

Editing the code itself

The next step is to edit the actual code so you need to either connect to your web server through FTP, a file manager or you may also use the Theme Editor inside of the WordPress Dashboard which can be found under the Appearance section labeled as Editor in 2.7. Once you have either header.php or sidebar.php open you need to search for a line of code depending whether you are wanting to hide a page link or a category link.

When looking for the code that displays pages you want to find

<?php wp_list_pages(); ?>

Or for the category code

<?php wp_list_categories(); >

As a quick note you may or may not see extra text within the () in the code. Whether or not you do see it does not matter as we are going to be inserting code in between the () anyways. We are going to be using &exclude= followed by the id of the page or category in order to prevent it from showing.

For example, lets say that the page you are wanting to hide has an id of 5. In order to hide it you would need the code to look like

<?php wp_list_pages('&exclude=5'); ?>

Or if the category you were wanting to hide had an id of 32 the code would look like

<?php wp_list_categories('&exclude=32'); ?>

Simple enough? As you can see, the id of the page/category is listed after &exclude= which tells WordPress not to show the link.

Whats that? You want to hide multiple pages or categories you say? That’s easy!

All that you need to do is place a comma after the first id followed by the id of the next page or category.

<?php wp_list_pages('&exclude=5,25'); ?>

- Hides pages with ids of 5 and 25

<?php wp_list_categories('&exclude=10,43,85'); ?>

- Hides categories with ids of 10, 43 and 85

If you find that there is other code listed inside of the () make sure that when adding in the code that you place an & in front of exclude= in order to prevent an error.

There you have it, how to hide a page or category link from showing in a list. You may have gotten lucky and found that your theme was already using exclude and you just had to add in extra ids. If not, you can still see how easy it was anyways!

If you have any questions or can’t get this to work on your WordPress theme feel free to leave a comment below :)

Feedback!

If you read this post and understood it great! Let me know in the comments below. If you are still having issues and can't get it figured out, you are more than welcome to leave a comment or send me an email using the contact form and I'll do what I can to help!

Leave a Reply