WordPress Tutorials

Hide Specific Post / Page From WordPress Search Results

There are few ways you can hide Specific posts, Page from WordPress search results. So let’s dive in find out different ways you can achieve it.

Method 1: Plugins

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.

Option 1 – Search Exclude Plugin

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 specific post or page

  • 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.

Method 2: Code Snippets

This Code will hide all the pages from search results and will only show posts in search results.

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');

This code removes a post type, in this case, pages, from search results when using the default WordPress search function.

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

Show More

Related Articles

Close