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.

This Plugin can hide any specific post or page, hide tag or category or anything in search results. Best thing is its Supports quick and bulk edit.

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

  • Ater, you Finish Installation. On any post, Page or category editor, you will see a checkbox on the right to exclude that post from search results.
hide any post or page from search
  • You can also hide your posts in bulk.
how to hide category or tags posts

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 and show only posts

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.

Also read: How to start a blog


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 on the 3rd line?

You can change word portfolio 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 Comment