Copied!
It's on your clipboard.
You’ve been offline for 0 second. Please check your Internet connection.

Help Us Improve

Found an issue or have an idea? Let us know.
Select all that apply...
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Exclude Specific Pages or Posts from Search
Preview
Download Template
Report Bug

Info

Resource
CMS
Builder
Elementor
Add-ons
No items found.
Last Updated
Jan 2, 2026

Overview

This snippet hides selected pages from WordPress search results by using their page IDs.

This is useful for hiding thank-you pages, private landing pages, or any content you want excluded from search results while still accessible via direct link.

Features

Setup

01
Add External Scripts

Copy & paste the scripts before the </body> tag of your project. If you added them before for another setup, skip this step.

Language
Copy
01
Copy structure to Elementor

Right-click in Elementor, choose “Paste from another site,” and while the popup is open, press cmd/ctrl + v to insert the layout.

Copy To Elementor
01
Add HTML

Place the code in an HTML widget or add it through Elementor → Custom Code (before the closing </body> tag) either globally or only on selected pages.

Language
Copy
01
Add custom CSS

Paste the code through the page or site settings, or add it via Elementor → Custom Code (before </body>) for broader use.

Language
Copy
01
Add custom Javascript

Paste the script through Elementor → Custom Code (set to load after </body>) for site-wide or page-specific loading.

Language
Copy
01
Add custom PHP

Place the PHP snippet inside your theme’s functions.php or using any code snippet to enable logic.

Language
Copy
function exclude_pages_search( $query ) {
    if ( $query->is_search() && ! is_admin() ) {
        $query->set( 'post__not_in', array( 12, 34, 56 ) ); // page IDs
    }
}
add_action( 'pre_get_posts', 'exclude_pages_search' );
01

To find a post or page ID, go to Pages (or any post type) in your WordPress dashboard and hover over an item. The ID appears in the browser link, usually as post=123.

Replace the example numbers in the code with those IDs.

You can also use a plugin like Show IDs to display IDs directly in the admin list.

01
Publish and preview live
Some solutions only work on the live site. Always publish and test after each change, as results may not appear in the editor.

Implementation