There are times when you'll want to set up a WordPress page for whatever reason, but you don't want the page to be included in WordPress search results. This snippet will enable that feature.
Remove All Pages from Search Results
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
This function will search for the post type of post. However, you could alter the post type to pages
if you wanted to only render pages in the search results.
Remove Specific Pages or Posts from Search Results
Copy and paste the WordPress function into your theme's functions.php
file or, if you sensibly have one installed, your custom functions plugin.
The array (25, 45)
on line 3 contains either the page or post ID that you don't want to appear in search results. In this case, it's the page/post ID's of 25 and 45.