I recently implemented a Google Custom search on this blog by following some good advice from Maki on how to set up Google custom search. The steps included creating a new page and adding the Google Custom search code to it, all went fine with the setup, but I came across a problem where I did not want the page to show up in the menu that is there at the top of this page.
The reason was that the title was too long and it was breaking the page and that I did not want it to be a part of the main menu.
Below is a screen shot of how the page was breaking the entire menu. If you see the page title was not aligning properly with the menu.
Now I did not want the page to appear this way so I found out a way I could exclude this page from showing up in the menu list. It is quite simple and requires you to modify your theme a bit. Let’s look at how exactly this can be done.
wp_list_pages is a WordPress method that allows you to list the pages that are available on your blog, you can add this code to your theme wherever you want the list of pages to appear. In case of this blog I am using the list pages as a navigation menu.
wp_list_pages function accepts different parameters and one of them is the pages that you want to exclude from appearing in the list.
Lets see how you can exclude certain pages by following the simple instructions given below.
Get the page id(s)
You will require the page ids in order to exclude them from showing up in the list. For this you will have to login to your admin panel and go to Manage -> Pages. The id of the page will be displayed along with the page names, you have to make note off this id, or multiple ids for the pages you want to exclude from showing up.
Changing the theme code
Once you have the id, open the theme editor and edit the file where you have used the wp_list_pages code. You need to add a parameter named exclude to the existing parameters used for the method.
Below is the modified code for this blog using which I excluded the page from showing up in the list;
If you see the above code I have added an extra parameter exclude=340, this will tell the WordPress code to exclude the page with id 340 from showing up in the list.
If you want to exclude multiple pages you need to separate each page with a comma, the multiple page excluding code will look the one given below.
That’s it once you have made the above changes to the code the page will not appear in the list. Below is a screen shot of the menu after excluding the page from the list.
You can use this on your blog too for the pages you do not want to appear in the list. Do let me know if this tip was helpful to you. Your comments are always welcome.