Last active
May 4, 2025 10:23
-
-
Save clivewalker/6dbc3478cf94218968ed to your computer and use it in GitHub Desktop.
WordPress page numbers with Yoast SEO plugin. Add to functions.php. This will add " - Page x" to titles and meta descriptions in paginated archives (categories, blog post archives).Based on http://www.htpcbeginner.com/resources/codes/page-number-meta-description.txt
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 page number to Yoast meta description and page titles to avoid duplication (when using customised titles/descriptions) | |
if ( ! function_exists( 'cvw_add_page_number' ) ) | |
{ | |
function cvw_add_page_number( $s ) | |
{ | |
global $page; | |
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; | |
! empty ( $page ) && 1 < $page && $paged = $page; | |
$paged > 1 && $s .= ' - ' . sprintf( __( 'Page %s' ), $paged ); | |
return $s; | |
} | |
add_filter( 'wpseo_metadesc', 'cvw_add_page_number', 100, 1 ); | |
add_filter( 'wpseo_title', 'cvw_add_page_number', 100, 1 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment