Edit Content
1. Why Remove Pages from WordPress Search Results?
1.1 Private or Restricted Content
2. Step-by-Step Guide to Remove Pages from WordPress Search Results
2.1 Method 1: Using the Search Exclude Plugin
2.1.1 Step 1: Install and Activate the Plugin
2.1.2 Step 2: Exclude Posts or Pages from Search
2.1.3 Step 3: View Excluded Posts or Pages
2.2 Method 2: Modifying the functions.php File
2.2.1 Step 1: Access the functions.php File
2.2.2 Step 2: Add Custom Code to Exclude Pages
2.2.3 Step 3: Test Your Changes
3. The Impact of Removing Pages from Search Results
3.1 Effects on SEO and Analytics
3.2 Monitoring Performance After Changes
Before diving into the “how,” let’s understand the “why.” Removing certain pages from your WordPress search results can significantly improve your site’s usability and user experience. Here are the top reasons:
Some pages on your site may contain private or restricted content meant only for specific users. For example:
Excluding these pages ensures they don’t show up in public search results.
Certain pages like “Thank You,” “Privacy Policy,” or “404 Error” often appear in search results but aren’t helpful to visitors. Removing them keeps your search results clean and focused.
When users search for something on your site, they expect quick and relevant results. Removing irrelevant or outdated pages helps them find what they’re looking for faster.
By excluding unnecessary pages, you ensure that your search results are neat, organized, and professional.
There are two primary methods to remove pages from WordPress search results: using a plugin or modifying the functions.php file. Let’s explore both methods in detail.
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:
After installation, click Activate .
Click Update or Publish to save your changes.
If you prefer not to use a plugin, you can 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:
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.
Copy and paste the following code into the functions.php file:
if (!is_admin()) {
function exclude_pages_from_search($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘post’); // Only show posts in search results
}
return $query;
}
add_filter(‘pre_get_posts’, ‘exclude_pages_from_search’);
}
This code ensures that only posts (and not pages) appear in your search results.
If you want to exclude posts and show only pages, replace ‘post‘ with ‘page’ in the code above.
Removing pages from your WordPress search results can have several effects on your site:
After making changes, keep an eye on your site’s statistics or analytics for a few weeks. This will help you understand the impact and make adjustments if needed.
You can hide pages using plugins like Search Exclude or by password-protecting them. Alternatively, you can add custom code to your functions.php file.
Go to Appearance > Menus in your dashboard. Uncheck the pages you want to exclude from the menu and save your changes.
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.
Removing 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!
We encompass a wide range of solutions, including eCommerce development, WordPress development, mobile app development, and digital marketing.