Do you want to learn how to exclude pages from the WordPress search results?
By default, the built-in WordPress search will include all posts and pages in its search results. To make it easier for visitors to find what they’re looking for, you may want to exclude certain content, so it never appears in those results.
In this article, we’ll show you how to exclude certain pages from the WordPress search results, step-by-step.
Why Exclude Pages from WordPress Search Results?
The default WordPress search includes all your posts and pages in its search results. This may work for some websites that have a small amount of content.
However, if you’re running an online store, then you may want to hide pages like your account page, checkout page, thank you page, and more.
The same goes for anyone running membership websites or selling online courses. You’ll likely want to stop subscriber-only content from showing up in the search results.
With that said, let’s show you how to exclude pages from the WordPress search results.
Note: In this guide we’re focusing on on-site search, where a visitor uses your website’s search box to look through your content. If you want to exclude pages from Google search results, then you should see our guide on how to hide a WordPress page from Google.
Create a New WordPress Search Algorithm with a WordPress Plugin
The easiest way to exclude pages from the WordPress search results is by using the SearchWP plugin. It’s the best search plugin for WordPress used by over 30,000 websites.
It’s very easy to use and gives you complete control over your WordPress search results.
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 Settings » SearchWP and click the ‘License’ menu option.
Then, enter your license key into the ‘License’ box and click the ‘Activate’ button. You can find the license key by logging into your SearchWP account.
After that, you need to click on the ‘Engines’ menu option.
This takes you to a page where you can create the default search engine settings. Think of it like creating your own Google search algorithm that’s only for your WordPress blog.
With SearchWP, you need to create a sitewide search engine before you can start excluding pages from the search results.
To change the search engine settings, scroll to the ‘Posts’, ‘Pages’, or ‘Media’ section. Each section has an Application Attribute Relevance that will change how the search engine ranks your content.
For example, if you move the ‘Title’ slider to the left and the ‘Content’ slider to the right, then a matching search term in the content will carry more weight than a matching title.
To stop all pages from appearing in your WordPress website search results, scroll to the ‘Pages’ section. Then, click on its ‘Remove’ button.
This opens a popup where you can uncheck the ‘Pages’ box.
Then, simply click on the ‘Done’ button to exclude all pages from the search bar and results.
Once you’ve finished customizing the default search engine settings, you just need to save your changes.
To do this, click on the ‘Save Engines’ button.
At this point you may see a message asking you to rebuild the index. If this happens, then simply click on the ‘Rebuild Index’ button.
Exclude Specific Pages From the WordPress Search Results
Sometimes you may want to exclude specific pages from the search results, such as the WooCommerce checkout page.
To do this, we’ll be using the Exclude UI extension from SearchWP. In your WordPress dashboard, go to SearchWP » Extensions.
Here, find the Exclude UI extension and click on its ‘Install’ button.
After that, open the page that you want to exclude from the search results. In the right-hand menu, make sure the ‘Page’ tab is selected.
You can now go ahead and check the ‘Exclude from search’ box.
Then simply click the ‘Update’ button, and this page will no longer appear in the search results, even if a visitor searches for its exact page title.
If you want to hide more pages from the search results, then simply follow the process described above.
To exclude specific blog posts from WordPress search results, simply open that post for editing. Then, check the ‘Exclude from search’ box in the ‘Posts’ panel.
We hope this article helped you learn how to exclude pages from the WordPress search results. You may also want to see our beginner’s guide on how to get a free SSL certificate for your website and our best business phone services for small businesses.
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.
Gabriel says
Thanks a lot! Seems to work perfectly.
WPBeginner Support says
Glad our guide was helpful
Admin
joel araujo says
just what I needed, at the right time
thanks
WPBeginner Support says
Glad our guide could help
Admin
Ivan says
Thanks. This worked for me. I wanted to exclude gallery appears in search results and this code does exactly what I need. Thanks
Pete says
This is really basic. It would be nice to see how to exclude only particular page templates, or blog categories.
VishvjeetCheema says
You are true life savers. always.
Gautam Nagraj says
Hello team WPBeginner
I am facing a new problem
when I have tested crawled pages on Google by writing
site:example.com
Then it showing pages & posts properly but also showing pagination links
example.com/page/2/
Like this
So how can I avoid this?
Please help me.
Joni says
Thanks! :)!
Laura Rafferty says
Wondering if there’s a way to target different search forms with this technique. I’d like the main website search form to target pages only; and the blog search form to target posts only.
Val says
I have some pages that are password protected (via main WP option to password protect a page) but they are still showing up in WP search with the excerpts. My understanding is that by default, the excerpts should not appear, you should see “There is no excerpt because this is a protected post.” I can use the Simply Exclude plugin but I’m wondering why the excerpts are showing up in the first place and I’d rather not add another plugin if I don’t have to.
deny jackrose says
Thank you very much sir.. this post really help me.. you rock man .. !!
Victor says
Thank you very much. You guys did the trick. I was looking for this and couldn’t find it anywhere else.
Nice job, guys.
Noah says
When someone just hits SEARCH with the criteria being ‘blank’, ALL pages show up in the results. How can I have NO results show in this situation?
Jornes says
Noah, if you are saying about search result, you can validate the search form using javascript. So that people are forced to key in the words before do the searches.
Samsir Alam says
Thanks bro.
WPBeginner Staff says
Glad to hear. You are welcome.
Dimitra says
Thank you so much for the article and some comments with codes that helped me a lot!
Bijay Pakhrin says
Worked perfectly, Thanks alot
redimin says
Work Fine !
Bruno says
Thanks bro! Your code helped me a lot.
Henry says
This worked much better than passing a hidden field (which is what I’ve been doing).
Laura says
This worked great, thanks! How can I include WordPress Native BBPress forum topics in the search results?
Thanks,
L
WPBeginner Support says
You can try bbpress search plugin.
Admin
Jornes says
Hi! I would like to ask how do i exclude the specified pages i wanted to excluded from searches? And how do i know what is the ID of the page? Can someone tell a solution? I wanted to excluded some pages which are useless to visitors.
Thank you!
hamza says
works for me. thank you!
Spyridon says
You are a real life saver. I tried codes from WordPress forum but didn’t work out. Yours is working for me!
luckyankit says
Well just wanted to say thank you for this… wonderful article
gormanIT says
Can you alter this function to exclude specific pages/posts from search? Ive been searching for this functionality and havent found anything.
David Allred says
Perfect! I was expecting it to be a bit more complex than that. Thanks a ton!
Michael Bailey says
Thank you so much. This was super helpful, fixing my problem with the speed of a cut and a paste (and a test)..
Success in all your ways!
Michael.
Katie says
Well, that’s almost perfect. I searched and found that many site’s offering us to hardcode the category ids to search id but this is cool. One question, i have to do the pagination myself so when i add this filter i won’t get offset issues .. right?
Editorial Staff says
No, you should not have offset issues.
Admin
Mohsen says
Hi
may I put your tutorials in my blog with a link to wpbeginner.com? my blog is in Farsi and I think many persian users need these tips.
thanks a lot
Editorial Staff says
No you may not translate any of our tutorials entirely. You may write a summary and then link to our site.
Admin
Rilwis says
This hack excludes not only pages from search results, but also other custom post types. So if we have many custom post types in our WP site, we can put them in the statement like this:
$query->set(‘post_type’, array(‘post’, ‘custom-post-type’));
Rein says
Thanks Rilwis, just what i needed!