您可以更改的链接next_post_link 和previous_post_link 使用过滤器。
function alter_npppl_wpse_100919($link) {
return preg_replace(\'/href="([^"]+)"/\',\'href="$1#something"\',$link);
}
add_filter(\'next_post_link\',\'alter_npppl_wpse_100919\');
add_filter(\'previous_post_link\',\'alter_npppl_wpse_100919\');
您获得的URL将是默认URL plus
#content. 如果您的站点正在生成
/page/2/ 那么最终的URL将是
/page/2/#content. 如果您不需要尾部斜杠-,在
#-- 您必须通过回调传递匹配。
function alter_npppl_noslash_cb_wpse_100919($match) {
return \'href="\'.untrailingslashit($match[1]).\'#content"\';
}
function alter_npppl_v2_wpse_100919($link) {
return preg_replace_callback(\'/href="([^"]+)"/\',\'alter_npppl_noslash_cb_wpse_100919\',$link);
}
function alter_npppl_wpse_100919($link) {
return preg_replace(\'/href="([^"]+)"/\',\'href="$1#something"\',$link);
}
add_filter(\'next_post_link\',\'alter_npppl_v2_wpse_100919\');
add_filter(\'previous_post_link\',\'alter_npppl_v2_wpse_100919\');
如果你的网站是使用尾部斜杠,我不会删除它。如果这样做的话,很可能会导致不必要的重定向。
#something 可以是任何id 在页面上。如果你有<div id="content" 然后添加#content 应该是因为div 在页面加载时滚动到视图。