Exclude Specific Posts and Pages from WordPress Search Results

/* Exclude Specific Posts and Pages from Search Results */
function wpflt_exclude_from_search_page_id( $query ) {
  if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
    $query->set( 'post__not_in', array( '1053', '1024', '17' ) );
  }}
add_action( 'pre_get_posts', 'wpflt_exclude_from_search_page_id' );

Add the above code to your child theme’s functions.php to filter/ exclude specific posts and pages from appearing in search results. By default, search function in WordPress fetches results from all page types.

Example, there can be a post on your site regarding ‘privacy policy’. When user searches for ‘privacy policy’, your own site’s privacy policy can appear along with the post related to it. You can disable that by adding the page ID of the specific post or page, inside the array (in line 4).