Steps
-
Add the PHP code to your theme’s
functions.phpfile or a PHP snippets plugin. -
Save and activate the snippet.
-
Open a search results page on your website.
-
View the page source and check for the robots meta tag.
/**
* Add noindex, follow to search result pages
*/
function custom_noindex_search_pages() {
if ( is_search() ) {
echo '<meta name="robots" content="noindex, follow">' . "n";
}
}
add_action( 'wp_head', 'custom_noindex_search_pages' );
Tested on
WordPress 6.8
Reported by the author on November 23, 2026. WPFolks has not verified this.
Not tested against WordPress 7.1.5. It may still work.
