How to Exclude Pages from WordPress Search Results

How to Exclude Pages from WordPress Search Results. By default, the internal search on your WordPress website will cover all posts and pages in the WordPress search results. To address it more relaxed for your site users to find what they’re looking for, you may require to exclude certain Pages or Posts, so it nevermore appears in those results.

In this article, you will learn how to exclude Pages or Posts from the WordPress search results. Let’s div.

Why Need to Exclude Pages from WordPress Search Results?

By default WordPress, site search covers all of your content in the search results. This works well full for various WordPress website owners. However, if you are managing an online store, then you may desire to hide pages like your account page, Welcome Page, checkout page, thank you page, etc. Also you may require to hide subscriber-only content from appearing in search.

Note: This guide meets on-site search results when a user uses your website search box to search through your website content. If you’re seeming to exclude content from Google search, then you should read our article on how to hide a WordPress page from Google.

Method: 1 Using PHP Code

So, first I will suggest you if you are familiar with coding then do it otherwise follow the other way. This function.php file is a kind of template used by a WordPress theme. This one automatically loads both in the admin and front-end pages of your WordPress website. It is used for specifying functions, actions, classes, and filters that other templates use within a certain theme.

The following code can be added to your functions.php file if you want to specify the search results to any selected page or post.

//Exclude pages from WordPress Search
if (!is_admin()) {
function wpb_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','wpb_search_filter');
}

This code will make sure that the search doesn’t come from the WP admin pages and then it will search for posts by setting the post_type parameter. You can also set the post_type parameter to pages to make it return the pages in the search results.

Method: 2 Using a Plugin

The most comfortable method to exclude pages or posts from the WordPress search results is by installing the Search Exclude plugin. It’s the most suitable search plugin for WordPress used by over 50,000 websites. It’s very simple to use and provides you with complete control of your WordPress search results.

The first thing you are required to do is install and activate the plugin.

Exclude Pages from WordPress
Exclude Pages from WordPress

After Installation, you just need to edit your Post/Page that you want to exclude from search results and then just select Exclude from Search Results as you can see in the above image. Now, Just click on Publish/Update button to save changes.

After that you can go to Settings >> Search Exclude and you will see the list of excluded posts or pages. Hope this was helpful.

Leave a Reply

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