hide posts from search results

How to Hide any Post or Page from Search Results

Do you want to hide any post or page from search results on your website?

There are few ways you can hide Specific posts, Page and even custom post types from WordPress search results.

  1. Search Exclude Plugin
  2. Hide all Pages
  3. Hide Custom Post Type

Hide any Post or Page from Search Results

Let’s dive in find out different ways you can remove posts, pages and custom posts from seach results.

1 Search Exclude Plugin

If you are not comfortable with code and want to use Plugin Instead that’s ok too. The significant benefit of using the plugin is you will not lose anything after upgrade your theme.

Search Exclude Plugin can hide any specific post or page, hide tags or category or anything in search results. You can also exclude posts in bulk instead of editing each post separately.

On the plugin settings page, you can also see the list of all the items that are hidden from search.

How To Use This Plugin

After you install the plugin edit the post, page, or custom post type that you want to exclude from the search result. On the edit screen, you will see an option to exclude that particular post or tax money from search results.

search exclude image

Other Plugins are also available

The Simply Exclude plugin will enable you to select which specific pages or posts you don’t want appearing in your sites search results.

The Search Everything plugin enables you to exclude posts and categories from displaying in the default WordPress search functions results.

2 Hide all pages from search Results

If you want to hide all pages and show only blog posts. This Code snippet will just do that.

function remove_pages_from_search($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','remove_pages_from_search');

After you add the above snippet in your theme’s functions.php file users won’t see any page in search results.


3 Hide Custom Post Types from search results

Now, if you have any custom type posts such as portfolio, properties etc., which you don’t want to show up in results and not intrested in using plugins I mentioned above.

This code snippet will remove any post type from search results when using the default WordPress search function.

function remove_post_type_page_from_search() {
    global $wp_post_types;
    $wp_post_types['portfolio']->exclude_from_search = true;
}
add_action('init', 'remove_post_type_page_from_search');

Notice the word portfolio in 2nd line? That is the name of the custom post type. You can change it according to the name of your custom post type.

I hope this article has helped you to hide any post or page from search results on your site. Let me know in the comments below if need any assistant.

Leave a Reply