Yes, it is possible to modify the title format for paginated posts in WordPress, including changing or removing the “Page 2” text that appears in link previews on social media. To do this, you’ll need to add some custom code to your theme’s functions.php file or a site-specific plugin.
The title format for paginated posts is typically controlled by the wp_title filter or document_title_parts filter in newer versions of WordPress. You can hook into this filter to modify the title based on the page number.
Here’s an example of how you might do this:
Using the document_title_parts Filter:
This filter is used in newer WordPress versions and is more flexible.
function wpb_customize_page_title( $title ) {
if ( is_singular() && is_paged() ) {
$page = get_query_var( 'page' );
if ( $page == 2 ) {
// Change the title for page 2
$title['title'] = $title['title'] . ' - English Version';
} else {
// Optional: remove page number for other pages
unset($title['page']);
}
}
return $title;
}
add_filter( 'document_title_parts', 'wpb_customize_page_title', 10, 1 );
Using the wp_title Filter:
If you’re using an older version of WordPress that doesn’t support document_title_parts, you can use the wp_title filter.
function wpb_customize_old_wp_title( $title, $sep ) {
if ( is_singular() && is_paged() ) {
$page = get_query_var( 'page' );
if ( $page == 2 ) {
// Change the title for page 2
return 'English Version ' . $sep . ' ' . $title;
}
}
return $title;
}
add_filter( 'wp_title', 'wpb_customize_old_wp_title', 10, 2 );
Remember to replace ‘English Version’ with whatever text you prefer, and adjust the conditions as needed for your specific setup. This code will alter the title for the second page of paginated posts. If you have different requirements for other pages or other languages, you may need to expand the conditions in the code.
Important Note: Always back up your site before making changes to the code, and ideally, test the changes in a staging environment first. If you’re not comfortable editing theme files, you might want to seek assistance from a developer.