Created
October 4, 2018 10:40
-
-
Save nickcernis/262229c601e5c67e5524358b11a7d274 to your computer and use it in GitHub Desktop.
noindex paginated homepage for Genesis / Yoast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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