How to remove pages from search results in WordPress

Removing pages from the search results can be a plus, specially when your visitors are looking for the rich content and not a page.

Open wp-content/themes/your-theme/functions.php, add the following:

// Removes pages from search results
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
return $query;


Simply remove the above code if you wish to allow pages to be shown again in search results.

Author: Ryan Kessen

Computer Repair, Freelancer, Blogger, Reviewer and all around nice guy!

One thought on “How to remove pages from search results in WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *