How could you exclude a page from search results?

you can exclude certain pages from WordPress search results. Add this code to your functions.php or make it a plugin.


function jp_search_filter( $query ) {
if ( $query->is_search && $query->is_main_query() ) {
$query->set( 'post__not_in', array( 10,11,20,105 ) );
}
}
add_action( 'pre_get_posts', 'jp_search_filter' );
 
Back
Top