Exclude the content of one page in the search bar

Hi everyone! I need a little help with my site.
I need to exclude the content of one page when I use the search bar. I’ve regulated the access to this page only with the compilation of a form (made ContentForm7), so the content of the page mustn’t appear when I search something with the search bar in the menu. How can I do this?
Thanks a lot!


Hi There,

It’s possible with the custom code.

First, you have to setup a child theme:

After that add this custom code under functions.php file locates in your child theme:

function search_filter($query) {
  if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
      $query->set('post__not_in', array(123));


The 123 number should be the post ID. To locate your post ID, please see this:

For more information about the pre_get_posts hook, please take a look at this:


Hope that helps and thank you for understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.