Quote:
Originally Posted by TheLegacy
what did chatgpt say about it? I asked the same question and got several answers.
also who do you host with?
|
actually chatgpt figure it out for me after a looooot of insults, suggestions and questions. here are the code to go in fuunctions.php, it will removed the noindex in wp-script themes and replace with index, this works only in pages with ?s= and /search/
function replace_robots_meta_tag_for_search($buffer) {
// Check if the current page has a query string 's=' (search query)
if ( isset($_GET['s']) && !empty($_GET['s']) ) {
// Replace noindex with index in the robots meta tag
$buffer = preg_replace_callback(
'/<meta\s+name=[\'"]robots[\'"]\s+content=[\'"]noindex,\s*follow[\'"]\s*\/?>/i',
function($matches) {
return "<meta name='robots' content='index, follow' />";
},
$buffer
);
}
return $buffer;
}
function start_replace_robots_buffer_for_search() {
ob_start('replace_robots_meta_tag_for_search');
}
add_action('template_redirect', 'start_replace_robots_buffer_for_search');
function replace_robots_meta_tag_for_pretty_search($buffer) {
if ( is_search() ) {
// Replace noindex with index in the robots meta tag
$buffer = preg_replace_callback(
'/<meta\s+name=[\'"]robots[\'"]\s+content=[\'"]noindex,\s*follow[\'"]\s*\/?>/i',
function($matches) {
return "<meta name='robots' content='index, follow' />";
},
$buffer
);
}
return $buffer;
}
function start_replace_robots_buffer_for_pretty_search() {
ob_start('replace_robots_meta_tag_for_pretty_searc h');
}
add_action('template_redirect', 'start_replace_robots_buffer_for_pretty_search');
the upper one is for ?s=
and below that one is for /search/
so it works individually