Avisos
Vaciar todo
Otros plugins
1
Respuestas
1
Usuarios
0
Reactions
623
Visitas
Dic 13, 2023 11:04 am
A veces no queremos que se indexe una página que tenga un parámetro determinado en la url, como puede ser "orderby"
add_action( 'wp_head', 'cp_prevent_indexing_orderby' );
if(!function_exists('cp_prevent_indexing_orderby')){
function cp_prevent_indexing_orderby () {
if (isset($_GET['orderby'])){
echo '<meta name="robots" content="noindex, nofollow">';
}
}
}
Con este código puedes meter un meta para decirle a los buscadores que no indexen ni sigan determinadas páginas que muestren el parámetro deseado en la url.
Pero si usas Yoast SEO, puedes usar otra forma:
add_filter( 'wpseo_robots', 'yoast_seo_robots_remove_single' );
/**
* Set certain posts to noindex nofollow
*/
function yoast_seo_robots_remove_single( $robots ) {
if (isset($_GET['orderby'])){
return 'noindex,nofollow';
} else {
return $robots;
}
}