In most case, it is not relevant to search in some of your internal pages. This is the case for your homes (front page and blog home page). The following snippet let you excludes those pages with the powerfull pre_get_posts filter.

function bweb_search_filter_exclude_frontpage( $query ) {
  if ( $query->is_search && $query->is_main_query() && !is_admin() ) {
add_action( 'pre_get_posts', 'bweb_search_filter_exclude_frontpage' );

All you have to do is to open your functions.php file (in your child theme) and paste the function.

Post written byBrice CAPOBIANCO

WordPress addict and self-taught. I love to learn and to create, then to share…
Founder of bweb.
Share this post

Your email address will not be published. Required fields are marked *