Why Exclude Pages from Search Results?
Think about it: When someone searches on your site, they’re probably looking for blog posts, not static pages like your “Contact” page or “Terms and Conditions.” Here’s why excluding pages from search results makes sense:
- Better Search Relevance: Visitors will find blog content instead of unrelated pages.
- Improved User Experience: A cleaner search helps users find what they’re looking for faster.
- SEO Benefits: Pages like “Privacy Policy” don’t need to show up in search results, preventing unnecessary indexing.
Let’s dive into three ways to make this happen.
Method 1: Use a Code Snippet (Best for Performance)
If you’re comfortable adding a small code snippet to your theme, this is the fastest and most efficient way to remove pages from search results.
Steps to Add the Code:
- Log in to your WordPress dashboard.
- Go to Appearance → Theme File Editor.
- Open the
functions.php
file of your active theme. - Paste the following code at the bottom:
function filter_elementor_search_results($query) {
if ($query->is_search() && !is_admin()) {
$query->set('post_type', 'post'); // Ensures only blog posts appear in search
}
}
add_action('pre_get_posts', 'filter_elementor_search_results');
How This Works:
- This code checks if the search is happening on the front end of the site.
- It then tells WordPress to only include blog posts in the search results, excluding pages automatically.
If you want to exclude specific pages instead of all pages, you can modify the code like this:
function filter_elementor_search_results($query) {
if ($query->is_search() && !is_admin()) {
$query->set('post__not_in', array(123, 456)); // Replace 123, 456 with actual page IDs
}
}
add_action('pre_get_posts', 'filter_elementor_search_results');
To find your page IDs, go to Pages → All Pages, hover over a page title, and look for the ID number in the URL.
This method is great if you want a lightweight, permanent solution without relying on extra plugins.
Method 2: Adjust Elementor Pro Settings (No Coding Needed)
If you have Elementor Pro, you can easily modify the search results visually without touching any code.
Steps to Exclude Pages in Elementor Pro:
- Go to Templates → Theme Builder in WordPress.
- Open the Search Results template (or create one if it doesn’t exist).
- Click on the Posts Widget that displays search results.
- In the left sidebar, go to Query → Source and change it to Posts instead of “All”.
- Save your changes.
This method is perfect for those who prefer using Elementor’s drag-and-drop interface instead of coding.
Method 3: Use a Plugin (Best for Beginners)
If you’re not comfortable editing code and don’t have Elementor Pro, you can use a plugin like Search Exclude to hide pages from search results.
Steps to Exclude Pages with a Plugin:
- Go to Plugins → Add New in WordPress.
- Search for Search Exclude, install it, and activate it.
- Go to Pages → All Pages in your dashboard.
- Edit any page you want to exclude from search.
- Look for the “Exclude from Search Results” checkbox (usually at the bottom of the page editor) and check it.
- Save your changes.
This is the easiest solution for beginners who want full control over which pages appear in search results without touching code or using Elementor Pro.
Which Method is Best for You?
Here’s a quick rundown to help you decide:
- For a fast, code-free solution, use the Search Exclude plugin (Method 3).
- If you have Elementor Pro and prefer a visual approach, adjust the Search Results template (Method 2).
- If you want a lightweight, code-based solution without extra plugins, use the code snippet (Method 1).
No matter which method you choose, your Elementor search will now only show blog posts, making it more relevant and useful for visitors.
Get started today by reading our next post on SEO Tips for WordPress or check out our full guide on optimizing search results for even better performance!