Exclude Pages from WordPress Menus

How to Exclude Pages from WordPress Menus

Many pages are created for special events and once that event is over, the page is useless, at least until it comes back. In the meantime, you probably want to make sure you exclude those pages in WordPress menus.

WordPress menus are functional and they are important for site structure and navigation layout. Bad navigation can even impact your SEO rankings. And like most things in WordPress, there are multiple ways to achieve this. And none of them are very difficult.

In this article, I will show you two quick and easy ways to exclude pages from WordPress menus. This includes using code and a plugin.

Why Exclude Pages From A Menu?

There are quite a few reasons why you may want to exclude certain pages from your WordPress menus.

I used an event as an example at the start, so let’s go a bit further. Let’s say you build a special page for Christmas. That page is really only used in the month of December, after that, you really don’t want visitors to find it.

This is exactly the kind of page you want to exclude from a menu, but what about when it is in season? In that case, you want to exclude the page it is replacing.

Holidays are not the only use either. Another consideration is when you have special sales that are not tied to a major holiday. You may also want to exclude the Contact Us or Privacy pages. These are better left for the footer area.

The bottomline is that some pages may need to be excluded from the menus.

How to Exclude Pages From Menus

Method 1: Exclude Pages From Menus Using Code

You can easily exclude WordPress menu pages using a combination of code and page IDs. Most of the time the code line you need to find and change for this will be located in the sidebar.php file, though it sometimes can be located in other files.

Step 1: Locate the sidebar.php File

First, you need to find the necessary file to edit. In this case, it is the sidebar.php file. There are two main ways to access this file. First, you can use the Editor option (as shown below).

Or, alternatively, you could use the File Manager in your cPanel to locate the file. Accessing the file by either means will have the same result.

To access the sidebar.php file click on Appearance and select the Editor option.

Click on appearance then editor to access sidebar.php file

This will take you to the website file’s page where you can access the sidebar.php file.

Click on sidebar.php to access the file

Step 2: Enter the Necessary Code

Now you just need to edit the file. This may sound difficult, but in reality, all you need to do is locate one line of code and make a small change.

First, open that file and locate the following code:


All you actually need to do is fill in the information within the parentheses. So for example I will exclude two pages. They have a 7 and a 17 as the page ID respectively Replace that line of code with this line and save the changes.


Please note that the ID numbers 7 and 17 above in the line of code are page ID numbers. Those numbers are used in this example, but you would simply replace those page ID numbers with any pages you want to exclude from WordPress menus.

After that, just save the changes and you are done. There is no limit on the number of pages you can exclude, but make sure to separate them with a comma.

Method 2: Exclude Pages From Menus Using a Plugin

Another simple way to exclude pages in a WordPress menu is to use the Exclude Pages From Menu Plugin. This plugin provides an option in the page edit screen in the admin area that you can use to exclude pages from displaying in WordPress navigation menus.

Step 1: Install Exclude Pages From Menu

Let’s start by clicking on Plugins and selecting the Add New option on the left-hand admin panel.

Add New Plugin

Search for Exclude Pages From Menu in the available search box. This will pull up additional plugins that you may find helpful.

Exclude-Pages

Scroll down until you find the Exclude Pages From Menu plugin and click on the “Install Now” button and activate the plugin for use.

Install Plugin

Step 2: Exclude Pages From Menus

There are no options and the setup is done. It is a lightweight and easy-to-use plugin that will easily exclude WordPress menu pages. Just go to any page you have and you will see a “Exclude pages from menu” box. Check the box to exclude the page when needed.

Checkbox to Exclude Pages from WordPress Menus

As you can see both options provide you with a fast and simple way to exclude pages from WordPress menus. Simply, go through your website and exclude the necessary pages by checking the box.

If you change your mind, or perhaps an event has returned, you just need to check the box to restore it to the menu. Just remember to save the changes you make.

If you uninstall the plugin, all of the excluded pages will be restored to the menu.

Congratulations on learning how to exclude pages from the WordPress menu.

Keep Your Menus Compact

One of the biggest mistakes beginners make is when they include every page or post in their menu. You’ve probably encountered a situation where you expand a menu and you need to scroll down the page to see all of the options.

This is a perfect example of bad design, and it should never happen on a website in today’s world.

Instead, you need to prioritize what’s actually important on your menu. Or better yet, make multiple menus out of larger ones by separating them by content or category. If you have to ask if a menu is too big, it probably is.

What are some reasons you may want to exclude certain pages from menus? Do you prefer using the code option or the plugin option to complete this task?

1 thought on “How to Exclude Pages from WordPress Menus”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.