I’ve recently had a situation where a client needed a ‘Terms and Conditions’ page hidden from search so that it made it harder for competitors to find where their demo software was installed – this of course doesn’t deter users that have a link to the page – however this is how it was designed so that targetted clients could get access to the page however competitors couldn’t.

  1. function hide_page_search($query) {
  2. if ( $query->is_main_query() ) {
  4. if ($query->is_search) {
  5. $query->set('post__not_in', array(5231));
  6. }}}
  8. add_action('pre_get_posts','hide_page_search');

Replace the ‘5231’ with the ID of the page you want removed.

Add this into your functions.php and check your search results – one less result will now show.

If you want more pages removed just add them after the id with a seperated comma.. eg. ‘5231, 921, 7290’.

Leave a Reply

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