How to remove this from wordpress website ?

Discussion in 'Content Management' started by lowriderzzz, Oct 27, 2017.

  1. #1
    Hi there!

    Ok I want this question to be understood properly.

    I have a WordPress blog with lots of content in the form of articles published as posts. I have few pages as well. Yet I want some of the pages not to appear on the WordPress site when a search for relevant word is being performed.

    For instance I have articles with the topic of XYZ, and when a keyword of that topic is being placed in the search filed of the website itself (not google) , the results sometimes show a page that I would want to be displayed (like a thank you page for instance).

    So what can I do so certain pages don't appear when people write related term in the search field.

    * I've set Google to not index them, but that is not what I'm asking.

    Thank you!
     
    lowriderzzz, Oct 27, 2017 IP
  2. Nigel Lew

    Nigel Lew Notable Member

    Messages:
    4,642
    Likes Received:
    406
    Best Answers:
    21
    Trophy Points:
    295
  3. bluebelt91

    bluebelt91 Well-Known Member

    Messages:
    879
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    130
    #3
    You can either use above plugin or put below code in Wordpress theme's Function.php:

    function jp_search_filter( $query ) {
    if ( ! $query->is_admin && $query->is_search && $query->is_main_query() ) {
    $query->set( 'post__not_in', array( 20 ) );
    }
    }
    add_action( 'pre_get_posts', 'jp_search_filter' );

    In the above example page id 20 will be excluded from search
     
    bluebelt91, Nov 22, 2017 IP