How to Exclude Pages from WordPress Search Results without plugin


How to Exclude Pages from WordPress Search Results without plugin

Today I am going to show How to Exclude Pages from WordPress Search Results without plugin recently I create a Thankyou page for My contact form after that I click My WordPress search box without typing any text.it displaying the search page It shown My Thankyou pages, Hidden pages, and test pages I feel it’s not safe so I started a research for  Exclude Pages from WordPress Search Results.

Here is the Solution for this Filter all Pages from WordPress Search Results without plugins.

Add this Below PHP Snippet on your Themes functions.php file


function filterpagesinsearch($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts', 'filterpagesinsearch');

How it Works

post_type will control the search query the above code calls the post on WordPress search page result. it will Exclude the Pages in search results.

FAQ

1 – It will display mine all pages in Inbuild WordPress search result?

No, it will not display your page result in WordPress search

2, Whether it Hide my page from Google search result

No, it not hide your page from Google search result

Credit goes to Bavotasan

If you have any doubt on this Topic Please Feel Free to comment here I will Help you

Add a copyright notice to copied text in WordPress

How to add a copyright notice to copied text in WordPress without plugins

 



Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com