Here's a cool snippet to remove the WordPress Pages from search results.
Pretty straight forward, paste the following code inside your functions.php file:
/*-----------------------------------------------------------------------------------*/
/* Exclude pages from Search Results */
/*-----------------------------------------------------------------------------------*/
function exclude_pages_from_search() {
global $wp_post_types;
$wp_post_types['page']->exclude_from_search = true;
}
add_action('init', 'exclude_pages_from_search');
Code language: PHP (php)
You can also filter the WordPress Search by custom post type, if you need to 😉
Hi.. Great code.. but do you know a way of only Exclude or Include page that have a type of metadata value. Thanks!
Hi Erik,
This is a tough one. You can try to post your questions at http://wordpress.stackexchange.com/
Cheers.