If you’ve set up a search bar on your WordPress site using Elementor, you might have noticed that it shows both blog posts and pages in the results. This isn’t always ideal, especially if your site is primarily a blog and you don’t want visitors to land on static pages like “About Us” or “Privacy Policy.” In this guide, I’ll show you three ways to adjust Elementor’s search so that it only displays blog posts, making search results more useful and relevant.
Why Should You Exclude Pages from Search Results?
Think about this: If someone visits your website and searches for a topic, they’re probably looking for informative blog posts, not pages like your “Contact” form or “Terms and Conditions.” Here’s why filtering out pages makes sense:
- Better Search Relevance – Visitors will find actual blog content instead of static pages.
- Improved User Experience – A clean search function helps users find what they’re looking for quickly.
- SEO Benefits – Pages like “Privacy Policy” don’t need to appear in search results, preventing unnecessary indexing.
Let’s go over three ways to make this happen.
Method 1: Use a Code Snippet (Best for Performance)
If you’re comfortable adding a small piece of code to your WordPress theme, this is the most efficient way to remove pages from search results. Here’s how to do it:
Steps to Add the Code:
- Log in to your WordPress dashboard.
- Navigate to Appearance → Theme File Editor.
- Open the functions.php file of your active theme.
- Copy and 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 whether the search query is coming from the front end of your website.
- If it is, WordPress will only include blog posts in search results and exclude pages automatically.
If you only 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 the actual page IDs
}
}
add_action('pre_get_posts', 'filter_elementor_search_results');
To find your page IDs, go to Pages → All Pages in your WordPress dashboard, hover over a page title, and look for the number in the URL.
This method works well if you want a lightweight and permanent solution without relying on plugins.
Method 2: Adjust Elementor Pro Settings (No Coding Needed)
If you have Elementor Pro, you can modify search results visually without touching code.
Steps to Exclude Pages in Elementor Pro:
- Go to Templates → Theme Builder in WordPress.
- Select 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 editing code.
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.
- 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 those who want full control over which pages appear in search results without modifying code or using Elementor Pro.
Which Method is Best for You?
Here’s a quick summary to help you decide:
- If you want a fast and efficient fix without extra plugins, use the code snippet in Method 1.
- If you have Elementor Pro and prefer an easy, visual solution, adjust the Search Results template in Method 2.
- If you’re a beginner and want a simple, plugin-based solution, install Search Exclude from Method 3.
No matter which method you choose, your Elementor search will now only display blog posts, making it more relevant and useful for visitors.
Need Help?
If you have any questions or run into any issues, let me know in the comments below. Also, if this guide helped you, consider sharing it with others who might find it useful!
