admin管理员组文章数量:1126334
I use the nextpage tag on some of my posts in WordPress. Example: I write two different language versions of a post, write it both down in one post and cut it into two pages with the tag, so everyone can just view and share their language version. When someone shares the second page , the link preview on social media is showing as ‘THE NAME OF THE POST<<PAGE2’ which is not very pleasant for the viewers and looks strange, to be honest. As I use this ‘cutting’ method for language switching at the moment only, how do I rename this ‘Page 2’ text to ‘English version’ , for example, or remove it entirely? Is it possible?
I use the nextpage tag on some of my posts in WordPress. Example: I write two different language versions of a post, write it both down in one post and cut it into two pages with the tag, so everyone can just view and share their language version. When someone shares the second page , the link preview on social media is showing as ‘THE NAME OF THE POST<<PAGE2’ which is not very pleasant for the viewers and looks strange, to be honest. As I use this ‘cutting’ method for language switching at the moment only, how do I rename this ‘Page 2’ text to ‘English version’ , for example, or remove it entirely? Is it possible?
Share Improve this question asked Jan 19, 2024 at 16:37 shanshanarshanshanar 11 Answer
Reset to default 0Yes, 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.
本文标签: Changing Nextpage’s Preview
版权声明:本文标题:Changing Nextpage’s Preview 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736683325a1947535.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论