Created
June 30, 2020 15:32
-
-
Save darinronne/48e10f19ccf394740b05315c9563ad50 to your computer and use it in GitHub Desktop.
Filter Canonical URL for paginated pages - Wordpress, Yoast
This file contains 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
/** | |
* Filter Canonical URL for paginated pages. | |
* | |
* @param string $canonical The current page's generated canonical URL. | |
* | |
* @return string The filtered canonical URL. | |
*/ | |
function filter_wpseo_canonical( $canonical ) { | |
$a = '/page/'; | |
if ( strpos( $canonical, $a ) !== false ) { | |
$canonical = substr( $canonical, 0, strpos( $canonical, '/page/' ) ); | |
$canonical = $canonical . '/'; | |
} | |
return $canonical; | |
}; | |
add_filter( 'wpseo_canonical', 'filter_wpseo_canonical', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment