Skip to content

Instantly share code, notes, and snippets.

@darinronne
Created June 30, 2020 15:32
Show Gist options
  • Save darinronne/48e10f19ccf394740b05315c9563ad50 to your computer and use it in GitHub Desktop.
Save darinronne/48e10f19ccf394740b05315c9563ad50 to your computer and use it in GitHub Desktop.
Filter Canonical URL for paginated pages - Wordpress, Yoast
/**
* 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