Exclude posts and pages from search in wordpress easily, easy way to exclude pages or posts from search in wordpress, just 6 lines.

Using pre_get_posts action, we will exclude posts or page in wordpress.

Copy function code and paste it in your functions.php file.

Exclude Posts Function:

function WPTime_exclude_function($query) {
if ( $query->is_search() ) {
$query->set( 'post__not_in', array(125) );
add_action('pre_get_posts', 'WPTime_exclude_function');

Note: this array(125) an example for your post ID to exclude it,
Change this number 125 to your post/page ID to exclude it,
if you want to exclude more posts/pages, add your posts/pages ID using comma,
like this array(125,135,451) .