Welcome to Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy Praful Bhuskute BlackSpy

How to Remove Pages and Posts from Search Results in WordPress

How to Remove Pages and Posts from Search Results in WordPress

Here is code for removing pages from search in WordPress add the following code in a function.php file Just replace the array with your page ID’s
				
					
function exclude_pages_from_search($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
      $query->set('post__not_in', array(3031,2958,2926));
    }
  }
}

add_action('pre_get_posts','exclude_pages_from_search');
				
			

Drop your queries

Table of Contents

Have A Project In Mind? Let's Get To Work