Skip to content

Instantly share code, notes, and snippets.

@nickcernis
Created October 4, 2018 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickcernis/262229c601e5c67e5524358b11a7d274 to your computer and use it in GitHub Desktop.
Save nickcernis/262229c601e5c67e5524358b11a7d274 to your computer and use it in GitHub Desktop.
noindex paginated homepage for Genesis / Yoast
<?php
add_filter( 'genesis_get_robots_meta_content', 'sp_noindex_paginated_front_page' );
/**
* No-index paginated front-page if Genesis SEO is in use.
*
* @param array $directives The robots directives.
* @return array The directives with noindex set if on a paginated front page.
*/
function sp_noindex_paginated_front_page( $directives ) {
if ( is_front_page() && is_paged() ) {
$directives['noindex'] = 'noindex';
}
return $directives;
}
<?php
add_filter( 'wpseo_robots', 'sp_yoast_noindex_paginated_front_page' );
/**
* No-index paginated homepage for Yoast SEO.
*
* @param string $robots Current robots meta value.
* @return string Updated robots meta value.
*/
function sp_yoast_noindex_paginated_front_page( $robots ) {
if ( ! ( is_front_page() && is_paged() ) ) {
return $robots;
}
if ( '' === $robots ) {
return 'noindex';
}
return $robots . ',noindex';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment