Skip to content

Instantly share code, notes, and snippets.

View mcknightd's full-sized avatar

David McKnight mcknightd

  • Fosforus
  • Austin, Texas
View GitHub Profile
@mcknightd
mcknightd / functions.php
Created September 26, 2023 19:38
Exclude posts from wordpress search that have the yoast setting for 'allow search engines to index' set to 'no'
<?php
// add the below code to your child theme functions file
// exclude yoast noindex pages from wp search
function exclude_noindex_from_search( $query ) {
if(is_admin() || !$query->is_main_query()) {
return;
}
if($query->is_search) {
$meta_query = array(