Another Step In hiding or excluding WordPress Pages

It has been maybe a year since I last wrote the script for hiding pages in WordPress.  Now, I’m rebooting one of the blog themes on an old site and I need to break out some skills that have grown a little stale. Its kind of like when you go through a corporate relocation and have to go back through the process of configuring your voice mail and can’t quite remember what you used to know how to do.

So I need to hide some of the pages (not posts) that appear in the menu section of my new blog theme.

hiding-pages-in-wordpress

For example maybe you have an About page and a Policy page and you do not want the Policy page to show up as a menu button in your theme, so you exclude it from the call so that only the About button shows up in the menu.  Then you put a simple little link to the policy page in the footer of your website as is customary for many sites.

I did a quick search and came up with an article by the Realivent, real estate marketing blog of all places. 

Its kind of cool to have some many Davinci types in the world these days that have so many talents!  :)

Anyway the article I found actually offered up some script that essentially seems to install a plugin or something in WordPress so that you can hide pages at a global level.  That was definitely interesting, but over kill for what I was looking for.

But in that article the writer, Matt, mentioned covering several examples in the past.  This time he updated it with ways to both exclude specific pages and to include specific pages.

I was in the market for excluding and jumped over to his older article and found this:

The last way is to hardcode your menu function. Wordpress created the menu with this function: wp_list_pages();
You can either remove that function and add your own links, or add the “exclude” argument to wp_list_pages() like so:
wp_list_pages(exclude=17,38);

How to hide Pages in wordpress

Now that code if I am not mistaken has an error in it.  The exclude section should have quotes around it and should look like this (I think Matt corrected this in his second article, but I couldn’t follow his train of thought to see if he actually did or didn’t fix it.  He mentions fixing it, but I do not see the big red arrow pointing to an example of the fix.

(‘exclude=17,38′)

My Addition to this coding Saga

I had to make a few special additions to the code and I’d thought I offer up my own examples in case anyone else runs into having to combine the exclude or include commands for pages into a line of code that already has other commands running in it.

Before I started I had this in my list_pages line

<?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?>

 

After I added the exclude command (with an ‘&’ sign) it looked like this

<?php wp_list_pages('exclude=467&sort_column=menu_order&depth=1&title_li='); ?>

after-the-update-menu

Plus, I added my menu to the bottom of my site, but this time I included ALL pages.

<?php wp_list_pages('include=467,465,466,611,2&sort_column=menu_order&depth=1&title_li='); ?>
 
including-pages-wordpress-footer 
  • Share/Bookmark
Related posts:
  1. How to Do XML Redirects with New Blogger So you have graduated from Blogger to your own domain but you do not want to lose all those readers coming to your old blogspot...
  2. Adding RSS Feeds to All Categories Plugin Here’s a little plugin that I should have looked for a long time ago! It adds RSS feeds to all of your categories.  This is...
  3. Looking for the Best WordPress Plugin for Managing Internal & External Nofollow Links A partial plugin solution for managing nofollol links on internal links within WordPress....
  4. Transitioning from Blogger to WordPress Tip – Preventing Your Readers from Losing Touch or Getting Lost Back in 2006, I established a ‘junk’ blog.  It was supposed to be something that I would use primarily to practice creative writing or just...

8 Responses to “Another Step In hiding or excluding WordPress Pages”

  • John:

    I needed something like this for my clients website but it had to exclude categories. Thanks for the tip

    John

  • admin:

    Thanks for the comment John.

    I haven’t excluded categories before, but it should work in a similar manner

    try excluding with Cat_ID and the Category number, which you should be able to view in your Admin section under Manage Categories.

  • Great article. I wonder if I can apply similar code to a problem I am having with hover ads. I would like to include/exclude hover ads for a certain page or pages.

    I currently place my hover ad javascript in my various page templates and would love it if this type of include/exclude could be married to my hover code.

    Thoughts? Suggestions?

  • admin:

    Hi Michael,
    Thanks for the compliment. This include and exclude code is designed to include or exclude data in a MySQL database for wordpress which runs a code called PHP.

    If your javascript code somehow is calling ads that are actually loaded into a WordPress plugin, then this might work (although if its getting loadedup through javascript, a different coding language than php, I suspect it is not coming from a wordpress plugin.

    If it happens to be running in its own MySQL database, then you might be able to rewrite the code in php and skip the javascript, but I suspect that may be an even more advanced coding exercise for you than just copy/pasting javascript code in a template.

    Hope that helps you a bit, even if it just helps to rule out some possibilities so that you can focus on other options.

  • I am in the market for actually excluding pages from the robots as well. I have deleted some pages from my blog but it seems google still tries to access the page. I appreciate you post. I will report back if I find anything out. Thanks again

  • Baniuncodadup:

    What is bumburbia?

  • Jen:

    Thanks so much! This is one of those rare times when I try a WP edit and it worked on the first try! I appreciate it.

  • I do understand that frustration. :)

Twitter Tools
Archives
Translator
English flagItalian flagKorean flagChinese (Simplified) flagChinese (Traditional) flagPortuguese flagGerman flagFrench flagSpanish flagJapanese flag
Arabic flagRussian flagGreek flagDutch flagBulgarian flagCzech flagCroatian flagDanish flagFinnish flagHindi flag
Polish flagRomanian flagSwedish flagNorwegian flagCatalan flagFilipino flagHebrew flagIndonesian flagLatvian flagLithuanian flag
Serbian flagSlovak flagSlovenian flagUkrainian flagVietnamese flagAlbanian flagEstonian flagGalician flagMaltese flagThai flag
Turkish flagHungarian flagBelarus flagIrish flagIcelandic flagMacedonian flagMalay flagPersian flag  

Valid CSS!

ss_blog_claim=610ce799b239e79251b6e63cc094914d ss_blog_claim=610ce799b239e79251b6e63cc094914d