• Skip to primary navigation
  • Skip to main content

Genesis Community

Resources for Genesis WordPress Theme Users

  • Facebook
  • Twitter
  • Slack
  • Wiki
  • Login
You are here: Home / Wikis / WordPress / Remove landing pages from the search results

Remove landing pages from the search results

Code to remove landing pages from site search results. Assumes that templates are in the templates directory inside the theme.

add_action( 'pre_get_posts', 'leaven_search_hide_landing_page' );
/**
 * Removes landing pages from the search results.
 *
 * @param $query \WP_Query
 *
 * @return mixed
 */
function leaven_search_hide_landing_page( $query ) {

    if ( $query->is_search && $query->is_main_query() && ! is_admin() ) {
        $query->set( 'meta_query', array(
            'relation' => 'OR',
            array(
                'key'     => '_wp_page_template',
                'compare' => 'NOT EXISTS',
            ),
            array(
                'key'     => '_wp_page_template',
                'value'   => 'templates/page_landing.php',
                'compare' => '!=',
            ),
        ) );
    }

    return $query;

}
Source: https://gist.github.com/robincornett/d7ca5d1d898642ba4e93d45b88d9f3ce

Posted by: Sridhar Katakam Category: WordPress Tags: pre_get_posts, robin cornett

« Restrict searches to posts only
Remove the WordPress version from the head tag »

Copyright © 2026 · Genesis Sample on Genesis Framework · WordPress · Log in