How to Exclude Pages from WordPress Search Results: A Step-by-Step Guide

Have you ever noticed irrelevant or outdated pages popping up in your WordPress site’s search results, frustrating your visitors and making it harder for them to find what they’re looking for? They can be admin pages, thank-you pages, or outdated content, these unnecessary results can clutter the search experience and harm user satisfaction.

The good news is, there’s a solution! By learning how to exclude specific pages from WordPress search results, you can streamline the search process, improve user experience, and ensure visitors find exactly what they need—quickly and effortlessly.

Professional WordPress developers often use these techniques to optimize websites. In this blog, we’ll discuss simple yet effective methods to take control of your WordPress search functionality and keep your results clean and relevant. Let’s dive in!

Why Exclude Pages from WordPress Search Results?

Imagine you’re searching for something on a website, but instead of finding what you need, you see pages like “Thank You” or “Privacy Policy” in the results. Annoying, right? That’s why excluding certain pages from WordPress search results is important.

Some of the main reasons to exclude are:

Private or Restricted Content:

  • You might have private posts or pages meant only for specific users. Excluding them ensures they don’t show up in search results for everyone.
  • If your site has paid content, you don’t want users without permission to find it through search.

Avoid Irrelevant Pages: Some pages, like the Homepage or Author Page, often show up in search results but aren’t helpful to visitors. Excluding them keeps results clean and relevant.

Better User Experience: Visitors want quick, relevant results. Removing unnecessary pages helps them find what they’re looking for faster.

Cleaner Search Results: Excluding irrelevant pages (like admin pages or drafts) keeps your search results neat and useful.

Focus on Important Content: Highlight the pages that truly matter, like blog posts or product pages, instead of clutter.

Avoid Confusion: Pages like “404 Error” or “Login” don’t need to show up in searches. Removing them avoids confusion.

Simply put, when you hide certain posts or pages from WordPress search results, it helps people find what they’re looking for quicker and without any hassle.

Transform Your Website with Our WordPress Development Services!

Step-by-Step Guide to Exclude Pages From WordPress Search Results

There are two ways by which you can exclude pages from WordPress search results. The first method is by using a plugin and the second method is by modifying functions.php file. Let’s discuss both these methods in detail.

Using Search Exclude Plugin

The Search Exclude plugin is a lightweight and easy-to-use tool that lets you hide specific posts or pages from your WordPress search results. Here’s how to use it:
Step 1: Install and Activate the Plugin

  • Go to your WordPress admin dashboard.
  • Navigate to Plugins > Add New.
  • In the search bar, type “Search Exclude” and press Enter.
  • Locate the plugin and click “Install Now.”
  • After installation, click “Activate.”

Step 2: Exclude Posts or Pages from Search

  • Open any post or page in the WordPress editor.
  • On the right side of the editor, you’ll see a new checkbox titled “Search Exclude.”
  • To hide the post or page from search results, simply check the box.
  • Click “Update” or “Publish” to save your changes.

Step 3: View Excluded Posts or Pages

  • To see a list of all the posts and pages you’ve excluded, go to Settings > Search Exclude in your WordPress dashboard.
  • This page shows everything you’ve hidden from search results, making it easy to track and manage.

Bonus Tips

  • Quick and Bulk Edit: The plugin supports quick and bulk editing, so you can exclude multiple posts or pages at once.
  • No SEO Impact: Excluding pages from search won’t affect your SEO. Your sitemap will still include these posts or pages.
  • Fix Mistakes: If you notice a drop in traffic for a post, check the excluded list to ensure it wasn’t accidentally hidden.

In just a few simple steps, the Search Exclude plugin helps you clean up your search results, making it easier for visitors to find exactly what they need.

Modifying the functions.php

You can also exclude posts or pages from WordPress search results by adding custom code to your theme’s functions.php file. Here’s how to do it:

Step 1: Access the functions.php File

  • Go to your WordPress admin dashboard.
  • Navigate to Appearance > Theme File Editor.
  • On the right side, under Theme Files, click on “Theme Functions (functions.php)” to open the file.

Note: Editing the functions.php file directly can be risky because updates to your theme may overwrite your changes. To avoid this, use a child theme if possible.

Step 2: Add the Code to Exclude Pages from Search

  • Copy the following code:
if (!is_admin()) {
  function search_filter_posts($query) {
    if ($query->is_search) {
      $query->set('post_type', 'post');
    }
    return $query;
  }
  add_filter('pre_get_posts','search_filter_posts');
}
  • Paste the code at the bottom of the functions.php file.
  • Click “Update File” to save your changes.

What Does This Code Do?

  • It ensures the search is not coming from the WordPress admin area.
  • It forces the search results to show only posts by setting the post_type parameter to post, effectively excluding pages from search results.

Step 3: (Optional) Exclude Posts and Show Only Pages

If you want to do the opposite—exclude posts and show only pages—use this code instead:

  • Copy the following code:
if (!is_admin()) {
  function search_filter_pages($query) {
    if ($query->is_search) {
      $query->set('post_type', 'page');
    }
    return $query;
  }
  add_filter('pre_get_posts','search_filter_pages');
}
  • Paste it into the functions.php file and click “Update File.”

What Does This Code Do?

It forces the search results to show only pages by setting the post_type parameter to page, effectively excluding posts from search results.

Step 4: Test Your Changes

  • Go to your website’s front end and perform a search.
  • Check if the excluded content (posts or pages) no longer appears in the search results.

By adding a few lines of code to your functions.php file, you can easily customize your WordPress search results to exclude posts or pages. Just remember to use a child theme to avoid losing your changes during theme updates.

The Impact of Removing Pages from Search Results

When you exclude private or paid content from your site’s search results, it usually won’t affect your site statistics or analytics because these pages aren’t typically tracked in the first place. However, if you remove regular pages or posts from search results, you might notice a drop in their viewership—which is completely normal.

The good news is that even if you exclude a page from search, it will still be included in your sitemap. This means that if your SEO strategy is solid, the impact of removing a page (or even multiple pages) from search results shouldn’t be too significant.

That said, it’s important to remember that excluding pages reduces their visibility. To stay on top of things, check your site’s statistics or analytics a few weeks or months after making changes. This will help you understand the effects and make adjustments if needed.

Need Expert Help with Your WordPress Project? Let’s Discuss Today!

FAQs on Excluding Pages from WordPress Search Results

How do I hide pages in WordPress?
You can hide pages using plugins like Search Exclude (to remove them from search results) or Password Protect WordPress (to make them private). Alternatively, add custom code to your functions.php file.
How do I exclude pages from the menu in WordPress?
Go to Appearance > Menus in your dashboard. Uncheck the pages you want to exclude from the menu and save your changes.
How do I exclude a page from cache in WordPress?
If you’re using a caching plugin like WP Rocket or W3 Total Cache, go to the plugin’s settings and add the page URL to the exclusion list. This prevents the page from being cached.

Let’s Summarize

Excluding pages from WordPress search results is a great way to improve your site’s user experience. Whether you’re hiding private content, paid material, or irrelevant pages, tools like the Search Exclude plugin or custom code in the functions.php file make the process quick and hassle-free.

By streamlining your search results, you help visitors find what they need faster, while keeping unnecessary or restricted content out of sight. Just remember to monitor your site’s analytics after making changes to ensure everything works as intended.

With these easy steps, you can control your WordPress search functionality and create a cleaner, more efficient website for your users. If you need professional help with your site, our expert WordPress developers are here to assist you!

author
Chinmay Pandya is an accomplished tech enthusiast specializing in PHP, WordPress, and Laravel. With a solid background in web development, he brings expertise in crafting innovative solutions and optimizing performance for various projects.

Leave a comment