How to Exclude Pages from WordPress Search Results


WordPress search shows both posts and pages in search results. But pages don’t add much value in search. So, you can exclude pages from search results. In this article, I will tell you how to exclude pages from WordPress searches. I will also tell you the way to exclude only certain pages from the search.

Exclude All Pages from WordPress Search

If you want to prevent all pages from displaying in the search result, you can use the following code snipped and add it to the functions.php file.

Best Managed WordPress Hosting

WPEngine is the best and most secure managed hosting provider
function twg_search_filter($query)
if ($query->is_search)
$query->set('post_type', 'post');
return $query;

If you also have a few custom post types on your blog, you can set those custom posts in the code.

Exclude Certain Pages from WordPress Search

There’s a good WordPress plugin called Search Exclude. It lets you exclude pages and posts from WordPress searches. If you only want to exclude certain pages, use this plugin. This plugin adds an option to the page or post editor. You can select the checkbox to exclude a page from the search.

Now you know how to exclude all pages or certain pages from WordPress search. If you have a large website where you have several pages like terms, checkout page, profile page, and others that make no sense in search, exclude them from search.

Deepanker Verma is an experienced WordPress developer who has been working on WordPress for more than 12 years. On TheWPGuides, he writes about WordPress, WordPress development, and WordPress plugins.

Similar Articles


Leave a comment

Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.

© 2022 The WP Guides Developed By Deepanker