Looking to exclude pages from your WordPress search functionality? All you may need is to add this function your WordPress theme’s fucntions.php file.
3 answers
1
Excluding pages from WordPress search
To exclude pages from your WordPress search, you need to add the below function to your WordPress theme’s functions.php file.
- Navigate to Appearance > Editor > Theme Functions from your WordPress Dashboard;
- Copy and past in the code below;
- Click Update File to save the changes.
function exclude_pages_from_search() { global $wp_post_types; $wp_post_types['page']->exclude_from_search = true; } add_action( 'init', 'exclude_pages_from_search' );
— Support WizardAnswer 1
0
Excluding post types from WordPress search
You can use the above solution to also exclude other post types from your WordPress search.
$wp_post_types['your_post_type']->exclude_from_search = true;
— Support WizardAnswer 2
0
Excluding custom post types from WordPress search upon registration
To exclude custom post-types from your WordPress search, you can pass the argument below into when registering your post type.
'exclude_from_search' => true
— Support WizardAnswer 3