Exclude Page From WordPress Search

WordPress, by default search for post and pages. How ever you can add a filter to exclude page or post to make you search result effective.


Open your functions.php from your active theme and use the following Code.


function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post'); // Displays only post. Change it to 'pages' for pages.
}
return $query;
}

add_filter('pre_get_posts','SearchFilter');