This is the homepage for CleanCodeNZ Exclude Pages WordPress Plugin

Very often we would have to have some pages that should not appear on the navigation list, there is already one exclude pages plugin over there, what it does is attach a ‘hide page’ check box for every page, when it is checked then it will be saved into a list of excluded pages in option table. Then why another one?

This one is using custom field setting to hide pages, and plugin hook is wp_list_pages_excludes rather than get_pages which is a more general function, so it is done in a more intuitive and unobtrusive way. And code is times simpler, here is the key function


function cleancodenzexlp_getpagesidarray
($customfieldname,$customfieldvalue ) {
  
  $pagesidarray=array();

  if($customfieldname!=null && $customfieldname!=''
  &&$customfieldvalue!=null && $customfieldvalue!='')
  {
    $pagequeryargs= array(
             'meta_key'=>$customfieldname,
             'meta_value' => $customfieldvalue);

    $excludedpages = get_pages($pagequeryargs);

    if(count($excludedpages)>0)
    {
      foreach ($excludedpages as $excludedpage)
      {
        $pagesidarray[]= $excludedpage->ID;
      }
     
    }
     
  }
  return $pagesidarray;
}

The above function can get you all the pages that have a certain custom field name and value. There is a built-in function regarding custom field : get_post_meta() which is single page or post based. You obvious can use above function for general custom field searches.

So it is done through highly optimized cached general wordpress query and queried once for even hierarchical data, this would provide best performance and scalability.

No new database table or database field is created for this function.

A few screen shots:

1. Option setting for the custom field name and value

Option Page for cleancodenz exclude pages plugin

Option Page for cleancodenz exclude pages plugin

1.1. New option page for version 1.1, exclude pages from search function added.

Exclude from search

Exclude from search

1.2. In this version, support to hiding parent and child pages added.
1.3. Ver 2.0.0 is released,support for separate exclusion from search results added

2. Page edit screen shot

Page edit for cleancodenz exclude page plugin

Page edit for cleancodenz exclude page plugin

Download: CleanCodeNZ Exclude Pages Plugin from WordPress Plugin Directory.

Demo:
This page is a live demo, you can see that this is a page being excluded from the main menu, but you can find it in the site map pages list which will be picked up by search engines.

32 Responses to “CleanCodeNZ Exclude Pages WordPress Plugin”

  1. jonas says:

    Works fine in menus and archive but still shows up in my search result page.

  2. Jonah says:

    Simpler code, more general function, perhaps more robust and upgrade-proof, but having a simpler UI (tick-box versus custom field) is REALLY nice for non-power users. If there are benefits to more technically savvy users to the custom field approach, then keep it, but I suggest adding the tick-box option provided by Exclude Pages as well. IMO that’s why it has over 250K DLs.

    • CleanCodeNZ says:

      Good point, simpler code is not main point here, but speed is. While getting a hang of new stuff as customer field is not a bad thing as well.

  3. Eleanor Batchelder says:

    I only want to exclude a certain page (large table display) from search, not from menus or display. Is this possible?

  4. Eleanor Batchelder says:

    Can you tell me how to add a custom field? Is there an explanation somewhere on your site? Must I add a new one, or is it possible to use one that already exists on the page?

    • CleanCodeNZ says:

      On the page edit page, there is ‘add new custom field’ section where you can add a custom field and a matching value.
      You can use existing custom field for this plugin, as long as you copy your existing custom field and value to plugin option settings. Practically it is telling the plugin that please exclude pages that have custom field name and value as such. The plugin just works for pages when their custom field and value matches with what are set in option, it does nothing else. cheers

    • Kelli says:

      Good job making it apepar easy.

  5. Eleanor Batchelder says:

    Thanks! I got the new version, I added a custom field (thanks for telling me such an easy way to do that), and it works!

  6. Christopher says:

    Exclude a page from search – it is straight forward, easy and quick. Thank you!

  7. Kent says:

    Could this code exclude a page from listings as well? As for now it seems not too. A soon comning update?? :-))))))

    //Kent

    • CleanCodeNZ says:

      Hi Kent:
      Not sure what you mean by ‘listings’. it was written to exclude pages from page listing.Cheers

      • Kent says:

        Morning (in Sweden it is!) Mr Kiwi,
        On my site i have a menu for the main pages and i’m using i sidebar widget to show the subpages (we have over 500 pages, so that’s the solution we chose). Your brilliant solution remove the page i don’t want to show in the menu but not in the sidebar widget listing, unfortunately. It would be perfect if it did! Hope my pidgeon english is understandable?

  8. Kent says:

    Hello Mr Kiwi,
    I tried this excellent plugin on our site and it removed unwanted pages in the menu. Since we have a rather large number of pages (over 500) we have added a sidebar widget that lists pages and subpages to our aid. In this sidebar widget the unwanted page appears, unfortunately, even if we use your plugin. That’s what i mean with listings. Sorry for the pigeon english, Swedes are famous for it!

    • Kent says:

      Oops,
      i’m leaving lot’s of messages, sorry!

    • CleanCodeNZ says:

      Hi Kent:
      CleancodeNZ exclude is hooked on wp_list_pages() which is a standard way to list pages wherever you like, by saying that it is up to individual widget developer how to implement the listing of pages, if listing is not done through wp_list_pages() then excluded pages will not be consulted. You can do a simple search of wp_list_pages in your widget file to confirm my hunch. cheers

  9. Britt says:

    Can’t I use the exclude code of in my custom filed. I want to hide these page id’s in the menu navigation bar while in the shopping cart.

    • CleanCodeNZ says:

      You can. The core of excluding pages is function cleancodenzexlp_getpagesidarray, this gives back a list of page ids that have known custom field, instead of hooking this function to a filter as the plug in does, you can use this list and exclude them on your payment page menu navigation.

  10. Robin says:

    Hello, I’m trying to exclude all the child catergories of ‘models’. I followed your instructions but unfortunatly it doesn’t work. Maybe the template I use is part of the problem?!

    • CleanCodeNZ says:

      It is possible, plugins work with predefined hooks, if the template bypasses these hooks, functions will not be triggerd.

  11. Hey,

    I have found this to be the best most simple plugin out there on wordpress that does this function. I have used other plugins but this one seems to be the one with the least usage.

  12. At says:

    Hi, this looks like a great plugin, however it’s not working for me and I just wanted to check if I am missing something (probably). I am using version 2.0.0 and the activated plugin shows up in the plugins directory fine but the custom fields thing confuses me. You mention it’s in the page Edit Options but I can’t see that (WP3.4.2) I’m using the Custom Fields Plugin, but creating one through this doesn’t seem to work, at least not for hiding the page from search… Any help is much appreciated.

    • At says:

      OK, so I figured that ACF (Advanced Custom Fields) plugin was hiding the wordpress Custom Fields box from the screen options panel. Even after fixing that though (by updating to latest version of ACF) and creating a standard Custom Field, the post was still not omitted from search results. Sad face.

      • CleanCodeNZ says:

        Is it possible you disable ACF for a minute to see if it works? you are the first person who reported hiding page plugin did not work,this site has been upgraded to 3.4.2 and the plugin works as it is expected.

  13. MaxZieb says:

    How can I exclude all children from search by only marking the parent as non-searchable?

    • CleanCodeNZ says:

      You will have to add custom field and value to the pages you want to hide no matter they are at child or parent levels.

  14. Maritza says:

    Fine tips associated with this subject. Thanks so much for posting about it.

  15. Mike says:

    Hi,
    Any advice on how to use this plugin and add an ‘except for userID’ function?

Leave a Reply

*