Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To remove every Page from WordPress’s native front-end search, filter the main query with pre_get_posts and set its post type to post. Add the callback in a site-specific plugin or a child theme, then test the search form and any separate Ajax search your site uses.

Exclude all Pages from the native WordPress search

pre_get_posts runs after WordPress has built the query variables but before the query executes. The safeguards below limit the change to the front-end’s main search query, leaving dashboard searches and unrelated queries alone.

function freedom251_search_posts_only( $query ) {
    if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
        $query->set( 'post_type', 'post' );
    }
}
add_action( 'pre_get_posts', 'freedom251_search_posts_only' );

With this callback active, a native search URL such as /?s=term returns standard blog posts and omits Pages. Put the code in a custom plugin or a child theme’s functions.php; a child theme prevents a parent-theme update from overwriting it, while a plugin keeps the behavior independent of the theme.

Keep other content types searchable

Setting post_type to post is intentionally strict. If your site also searches products, documentation, or another custom post type, provide an explicit allow-list instead of broadening the query to any.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function freedom251_search_allowed_types( $query ) {
    if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) {
        $query->set( 'post_type', array( 'post', 'product', 'documentation' ) );
    }
}
add_action( 'pre_get_posts', 'freedom251_search_allowed_types' );

Use the registered post-type slugs, not their display names. An explicit array makes the intended result clear and avoids accidentally including content that should not be searchable.

Exclude a custom post type at registration

When an entire custom post type should stay out of front-end search, set exclude_from_search to true in its registration arguments.

register_post_type(
    'internal_doc',
    array(
        'label'               => 'Internal documents',
        'public'              => true,
        'exclude_from_search' => true,
        'supports'            => array( 'title', 'editor' ),
    )
);

This is a post-type-level rule: it applies to that type wherever WordPress honors the front-end search setting. Keep the registration in a plugin or must-use plugin so the post type and its search behavior do not vanish when the active theme changes. The default for exclude_from_search is derived from the post type’s public setting, so specify it when search visibility matters.

Hide only selected Pages without code

If only a handful of Pages should be hidden, a per-item approach is safer than changing every search query. The Search Exclude plugin adds an exclusion control to edit screens for Pages, Posts, and other content. Enable the setting on each item that should be omitted, then confirm that the plugin is currently maintained and compatible with your WordPress version before deploying it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This option leaves other Pages searchable and avoids maintaining PHP, but it adds a plugin dependency and may not control searches generated by a separate search provider.

Why Pages may still appear in a live Ajax search

The native browser search and a live-search dropdown can execute different queries. A theme, page builder, or search plugin may send an Ajax request that never uses the main front-end query changed above.

  • Identify which component handles the live results and whether it has its own post-type or exclusion setting.
  • Inspect the Ajax request and apply that provider’s documented filter or query argument.
  • Do not assume ! is_admin() is sufficient: during some Ajax requests, WordPress reports an administrative context, so a conventional callback can be skipped.
  • If the provider defines a separate query hook, target that hook; otherwise detect the Ajax request carefully and preserve the same allowed post-type list.

Test both the submitted search form and the live suggestions. A successful change to one does not prove that the other is using the same query.

Choose the right method

Requirement Method Main trade-off
Remove every Page from native search pre_get_posts with post_type => 'post' Requires PHP and changes the native main search query
Keep selected content types, but not Pages pre_get_posts with an explicit post-type array You must maintain the list as content types change
Exclude a whole custom post type exclude_from_search => true during registration Applies broadly to that post type and can affect other search consumers
Hide only particular Pages or posts Search Exclude plugin No code, but adds a plugin dependency and requires compatibility checks
Filter live Ajax results The search provider’s own filter or query setting Implementation varies by theme, builder, or plugin

Verify the change safely

  1. Back up the site or use staging before editing PHP.
  2. Install the callback in a custom plugin, must-use plugin, or child theme.
  3. Search for a term that exists in both a Page and a post; confirm only the permitted types appear.
  4. Open a dashboard search and confirm administrative results were not unintentionally altered.
  5. Test pagination, empty results, and search terms that match only a Page.
  6. Test any header search, live suggestions, builder widget, or mobile search separately.
  7. After changing a post-type registration or plugin setting, clear page, object, and search caches before retesting.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes

Pages still appear in the standard results page

Check that the callback is loaded, the search is the main query, and the code uses the correct post-type slug. A theme or plugin may also be replacing the query later in the request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Products or documentation disappear too

The callback is probably setting post_type to post. Replace it with an explicit array containing every type that should remain searchable.

The live dropdown is unchanged

That dropdown is likely using Ajax or a custom provider. Configure its post-type exclusions or attach to its query-specific hook rather than relying only on the native pre_get_posts callback.

The site breaks after editing functions.php

Restore the previous file through hosting tools or version control, check for a PHP syntax error, and move the final code into a site-specific plugin so theme changes are less risky.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.