Hiding Pages In WordPress

Filed under: Technology, Tutorials by: brennan

If you want to create a new page in your WordPress blog, but you don’t want it to show up as a link or button on your webpage, then this post should help you.

As you probably know, when you create a new page in WordPress, it automatically appears on your auto generated list of pages. A lot of the time, that’s not what we want to happen. For example, I wanted to create a new page in my blog called “Special Offers”, but I didn’t want to waste any space on my navigation bar. I just wanted a simple page that I could link to from another page. I did some research and here’s the solution I found:

Whenever someone views your blog, a special PHP function is called to display your list of pages. That function is called wp_list_pages(). If you want to exclude a specific page from being displayed in that list, you have to pass to it the parameter “exclude” and indicate the page ID you want it to skip.

So first of all, where do you find the function wp_list_pages()?

It’ll be in one of the PHP files you can edit from the WordPress “Theme Editor”. To get into it, open the “Design” tab in WordPress and click the “Theme Editor”:

Open The Theme Editor In WordPress

Open The Theme Editor In WordPress

Now depending on whether your page list is in the header or on the sidebar, you’ll have to go into the corresponding PHP file. In my case, the page list is on the header so I click on header.php:

Open The PHP File Where Your Pages Are Listed

Open The PHP File Where Your Pages Are Listed

Find the function wp_list_pages() in the code block. You can do this by using your web browser’s search feature. Press <ctrl>+<’f'> and type in “wp_list_pages”.

Find the wp_list_pages function

Find The wp_list_pages() Function

This is where you need to add the exclude parameter. So before ‘title_li= we need to enter “exclude=<page ID>”. So you know what page you want to hide but how do you find out what its ID is?

Go into “Manage” and select “Pages”. Find the page you want to exclude from the list and hover your mouse over it. In the status bar, you will see the page (post) ID:

Find Post ID In Status Bar

Find Post ID In Status Bar

Now go back into the Theme Editor and add the ‘exclude=461′ parameter to the wp_list_pages function:

Add The Exclude Parameter To The wp_list_pages Function

Add The Exclude Parameter To The wp_list_pages Function

*** Note: To block multiple pages use a comma between post numbers. Ex: (‘exclude=461,556,623&title….’)

Save the changes and refresh your blog. The link to that page should no longer be visible!

Related Posts

Tags: pages, wordpress

Leave a Reply

Wikipedia Affiliate Button