Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Exclude Specific Pages, Authors, and More from WordPress Search

By default, WordPress search includes all posts and pages in the search results. However, you may want to exclude some content, like your store’s checkout page, premium online courses, or subscriber-only content.

That way, your searchers won’t have to waste extra time scrolling through unnecessary or irrelevant results. This is especially useful if you run a site with a large blog post archive or an eCommerce store with lots of order-related pages.

At WPBeginner, we have published thousands of blog posts and have nearly 100 unique web pages. As a result, we know the importance of a streamlined search tool. In our experience, the best way to improve your search feature is by using plugins like SearchWP and WPCode. We use WPCode on our own blog, and some of our partner brands have had great experiences using SearchWP on their sites.

In this article, we will show you how to easily exclude specific pages, posts, authors, categories, and more from the WordPress search results.

How to exclude specific pages, authors, and more from WordPress search

Why Exclude Items From WordPress Search?

The default WordPress search shows results from all WordPress posts and pages, which works well for many websites.

However, sometimes, you may want to exclude certain pages and posts. For example, if you are running an online store, then you may want to remove the checkout and cart pages.

Similarly, if you manage a WordPress membership website or sell online courses, then you’ll typically want to exclude your premium, members-only content from public search results. You may even want to leave out other types of content, such as posts by specific authors.

That said, let’s take a look at how to easily exclude items from WordPress search. Here’s an overview of what we’ll show you how to do in this article:

Note: In this guide, we will show you how to exclude content from your website’s search results. However, this content will still show up in the search engine results. If you want to stop search engines from indexing a page, then check out our guide on how to hide a WordPress page from Google.

Install and Set Up the SearchWP WordPress Plugin

The easiest way to exclude pages, authors, categories, taxonomies, tags, and more is by using the SearchWP plugin. It’s the best WordPress search plugin used by over 30,000 sites.

SearchWP

It’s very beginner-friendly and makes it easy to improve the WordPress search feature to provide more helpful and relevant results. We explored its features in-depth when writing our detailed SearchWP review.

You can use this plugin to exclude entire content types from the search results. You can even exclude specific pages, posts, and custom post types.

The first thing you need to do is install and activate the plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, go to SearchWP » Settings and then click on the ‘General’ tab.

Activating the SearchWP search plugin

Here, you need to enter your license in the ‘License Key’ box.

You can find this information in your account on the SearchWP site. Once you are done, make sure to click the ‘Verify Key’ button.

Create a Custom Search Algorithm

After activating the plugin, you can fine-tune how SearchWP indexes, searches, and displays your content. You can think of this as creating a custom Google search algorithm that’s just for your WordPress blog or website.

You need to create a sitewide search engine before you can start excluding pages, posts, authors, and more from your custom search results page.

To get started, head over to SearchWP » Algorithm.

Creating a custom search algorithm in WordPress

Here, you’ll see a section for the different content types that SearchWP searches by default, such as pages, posts, and media files.

Every section has its own ‘Applicable Attribute Relevance’ sliders that control how SearchWP will rank your site’s content.

For example, if you move the ‘Title’ slider to the left and the ‘Content’ slider to the right, then the content will carry more weight than the title.

The SearchWP search algorithm settings

At this point, you can exclude entire content types from the search results, such as all pages, posts, and custom post types.

For example, most WordPress blogs have a few pages, such as a contact form or homepage. You may want to exclude all pages from the search so that only blog posts show up in the search results.

To do this, simply click the ‘Sources & Settings’ button.

Configuring the custom search algorithm in WordPress

This opens a popup where you can uncheck the content that you want to exclude from WordPress search, including all pages.

Once you’ve done that, click on the ‘Done’ button.

Excluding all pages from the WordPress search results

When you’ve finished customizing the default search engine settings, it’s time to save your changes. Even if you plan to exclude specific pages, authors, or other content, you’ll still need to save your new sitewide search algorithm first.

To do that, scroll to the top of the screen and click the ‘Save’ button.

Saving your site-wide search algorithm

SearchWP will now rebuild the index automatically. Depending on the speed of your Internet connection and your WordPress hosting provider, this may take a few minutes.

As soon as you see ‘Index Status 100%,’ you’ll know that SearchWP has indexed all your content and settings.

Rebuilding the WordPress search index using SearchWP

Now, the excluded content will never show up in the search results.

Exclude Specific Posts, Pages, and Custom Post Types from WordPress Search

Once you’ve created a custom search algorithm, you can exclude specific posts, pages, or custom post types from your WordPress search results.

For example, if you are using WooCommerce, then you might exclude your store’s contact form, account login, and checkout pages so that searches only ever return products. In this way, you can create a smarter WooCommerce product search and get more sales.

To do this, you’ll use the ‘Exclude UI’ extension, which adds an ‘Exclude from search’ box to the page editor.

In the WordPress dashboard, head over to SearchWP » Extensions. Here, find the ‘Exclude UI’ extension and click on its ‘Install’ button.

The Exclude UI search addon

After that, open the post, page, or custom post type that you want to exclude from the WordPress search results.

If you are excluding a single post, then make sure the ‘Post’ option is selected in the right-hand menu, then check the ‘Exclude from search’ box.

Exclude single post from search

With that done, click on ‘Update’ to save your changes.

You can also exclude specific pages and custom post types following the same process described above. The only difference is the right-hand menu will say ‘Page’, or the name of the custom post type, instead of ‘Post.’

You can also exclude specific categories, tags, and other custom taxonomies from the WordPress search results.

For example, there might be some tags that authors use to organize and manage content in your multi-author WordPress blog. Since these tags are just for your team’s reference, you’ll want to exclude them from the search results.

To do this, simply go to SearchWP » Algorithm and then scroll to the ‘Posts’ section. Here, click on ‘Edit Rules.’

Editing the SearchWP search rules

This opens a popup where you can edit the search engine rules.

Simply click the ‘Add Rule’ button to create your first rule.

Click add rule button

Here, open the first dropdown menu and select ‘Exclude entries if.’

You can now use the rest of the settings to specify the content you want to exclude. For example, if you wanted to exclude a specific category, then you’d type in the category name.

You can also type in any custom taxonomies you want to exclude.

Excluding categories from the WordPress search results

To exclude specific post tags from the search results, simply open the dropdown menu and select ‘Tags.’

Then, type in the name of the tag you want to exclude.

Exclude specific tags

To add another rule, simply click the ‘Add Rule’ button and repeat the same process described above.

When you are happy with how the rules are set up, click ‘Done.’

Once you have finished customizing your rules, make sure you scroll to the top of the page and click on ‘Save’ to store your changes and rebuild the index.

Rebuilding the WordPress search index

Now, when visitors search your WordPress website, SearchWP will exclude all the selected categories, tags, or custom taxonomies from its results.

If you’ve added multiple authors to your WordPress blog, then you may want to exclude specific authors from the search results. For example, you might exclude an author’s blogs if they’re no longer writing for your website.

You can exclude all the posts created by a specific author by adding code to your website. If you haven’t done this before, then see our beginner’s guide to pasting snippets from the web into WordPress.

Often, guides will ask you to add the custom code to your theme’s functions.php file. However, this isn’t very easy, and even a tiny spelling mistake or error in the code can cause common WordPress errors or even break your website completely.

Luckily, there is an easier way for users to add and manage custom code snippets.

WPCode is the most popular code snippet plugin used by over 1 million websites. It makes it easy to add code snippets without having to edit your functions.php file. You’ll also be able to update your WordPress theme without losing customizations.

The first thing you need to do is install and activate WPCode. For more details, see our step-by-step guide on how to install a WordPress plugin.

Upon activation, head over to Code Snippets » Add Snippet. Here, hover over ‘Add Your Custom Code’ and select ‘Use snippet’ when it appears.

Adding a custom code snippet to WordPress

This will take you to the ‘Create Custom Snippet’ page, where you can type in a name for the code snippet.

This is just for your reference, so you can use anything you want.

Adding a title to a custom WordPress code snippet

Next, open the ‘Code Type’ dropdown and select ‘PHP.’

After that, you can go ahead and paste the following snippet into the code box:

<?php
function wpb_search_filter( $query ) {
  if ( $query->is_search && !is_admin() )
    $query->set( 'author','-24' );
  return $query;
}
add_filter( 'pre_get_posts', 'wpb_search_filter' ); ?>

You’ll need to replace 24 with the user ID of the author you want to exclude. If you need help finding the user ID, then see our guide on how to find IDs in WordPress.

You can also exclude multiple authors from the search results by adding their user IDs separated by a comma:

<?php
function wpb_search_filter( $query ) {
  if ( $query->is_search && !is_admin() )
    $query->set( 'author','-24, -12, -19' );
  return $query;
}
add_filter( 'pre_get_posts', 'wpb_search_filter' ); ?>

Below the code box, you will see insertion options. There are two main insertion options: ‘Auto Insert’ and ‘Shortcode.’

You’ll want to choose the ‘Auto Insert’ method so that WPCode automatically inserts and executes the code across your entire site.

Auto inserting a custom WordPress code snippet

You can also assign tags to the code snippet. This can help sort your code snippets by topic and functionality.

When you are happy with how the snippet is set up, scroll to the top of the screen and click on ‘Save Snippet.’

Saving a WPCode WordPress code snippet

Finally, you can make the code snippet live on your site by clicking the ‘Active’ toggle.

Don’t forget to save this change by clicking on ‘Update.’

Activating a custom code snippet in WordPress

Now, the author will be excluded from the WordPress search results.

We hope this article helped you learn how to exclude specific pages, custom post types, authors, and more from WordPress search. You may also want to see our guides on how to customize the WordPress search results page and change the default search URL in WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

17 CommentsLeave a Reply

  1. Jiří Vaněk

    Thanks for the WP Code snippet. I also have articles on my blog that are hosted and I don’t want them to be searchable. Since I also have the author of the text registered with them, I can conveniently exclude them from the search thanks to your snippet. Thank you very much.

  2. Javier

    Hi!

    I have a doubt, it’s possible to exclude a word from search?

    For example:
    – Keyword to search: laptop
    – Not search with the word: macbook

    The results should be all the laptops but no the ones who contains the word “macbook”

    Thanks and regards!

    • WPBeginner Support

      That kind of customization would require editing how your search engine works, it would be better to use tags or categories for separating your content like that normally.

      Admin

  3. Dave C

    Hi,

    Will this affect SEO in any way?

    I want a specific post to be excluded from my own sites Searchbar, but still want it to be found by Google SERP’s.

    Thanks,

    • WPBeginner Support

      It will make your page more difficult to find and we have not tested but it shouldn’t have a major effect as long as the page can be easily found.

      Admin

  4. Melika

    Hi,
    The code in “Exclude Specific Tags from WordPress Search” section is faulty and causes WP to throw an error.

      • Melika

        Please look at the snippet once again. (I am only talking about the part after the heading which says “Exclude Specific Tags from WordPress Search”) First of all the syntax is wrong. on line 4 you have } but you have never started a block with {.
        Second, You have :
        add_filter( ‘pre_get_posts’, ‘wpb_search_filter’ );
        but never defined a function named : wpb_search_filter

        basically the code is missing one line at the type which should be :

        function wpb_search_filter( $query ) {

        So either it’s expected from the users to complete the code from what you added in the upper parts of this article or this snippet of code is not complete.

        • WPBeginner Support

          Thank you for clarifying that, it looks like our code block had a hiccup and we resolved the issue so the code should show correctly now. :)

  5. Brittany

    Hi there!

    By checking this “search exclude” will the post still be indexed and accessible via google?

    I’m trying to find the best way to have a post type available to those who have a link to it. However I do not want people to be able to access it via google or have to password protect the posts. Any suggestions for the best way to do that? (I can explain further if needed)

    Any help appreciated! Thanks :)

  6. Lisa

    Thank you so much for this post! I was having trouble not just with getting Google to stop indexing my Thank You page, but also preventing my own site from indexing it in the search as well! This solved both of my problems.

    • WPBeginner Support

      You’re welcome, glad our guide was able to help you :)

      Admin

  7. Claudia

    I have installed the plugin, checked the exclude check on one page but I continue to see on search result, why?

    • WPBeginner Support

      There are a few possible reasons. If you reach out to the plugin’s support they should be able to help you solve the issue :)

      Admin

  8. John

    Thanks for the VERY helpful post. As I am not a “coder,” I do have one question…

    How do I exclude **more than one** specific terms in a custom taxonomy? How will the code change?

  9. Deborah Smart

    Once I’ve excluded a certain page from a WP Search, do I have to change the setting from ‘Public’ to ‘Private’?
    I want to be able to give only certain people access to a certain page (for free information or paid information)- but they’re not editors on my blog.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.