While Elementor has a lot of features, there are instances when you wish to remove specific pages from search results. Elementor has become one of the most popular page builders, providing users with a robust and versatile tool for designing their websites.
This blog post will walk you through the process of properly concealing pages from search results, whether you have landing pages, thank you pages, or incomplete drafts that you don’t want people to stumble across.
Adding The Code
Place the following code at the bottom of your themes functions.php file;
- /wp-content/themes/your-active-theme/functions.php
- Save the file. Then go refresh your site and it should work.
## Exclude Pages From Search Results
if (!is_admin()) {
function wpsf_search_filter($query) {
if ($query->is_search) {
$query->set('post_type', array( 'post','product'));
}
return $query;
}
add_filter('pre_get_posts','wpsf_search_filter');
}
Conclusion
Hiding pages from Elementor search results is essential for keeping your website clean and user-friendly. You can simply regulate the visibility of your pages and guarantee that only relevant information shows in your website search results by following the procedure suggested in this tutorial.
Have Fun Blogging !!!