删除自动添加到分页 URL 的参数(自定义永久链接)

Remove automatically added parameters to pagination URLs (custom permalinks)

不知何故,当我将 wordpress 的 permalink 更改为自定义 permalink 时,分页 link 与以前不同。 Wordpress 或主题正在向我不喜欢的 url 添加查询参数。我已经尝试了一些在 Google 上找到的解决方案,但没有成功。

我的分页link是这样的:https://myurl.com/custom-permalink/page/2?q=custom-permalink%2F

我需要的就是这样:https://myurl.com/custom-permalink/page/2

谢天谢地,我通过这个 post 找到了解决方案:https://wordpress.stackexchange.com/a/78553

我只需要稍微更改一下代码,现在它按预期工作了,我得到了这样的分页 link:https://myurl.com/custom-permalink/page/2

只需将代码粘贴到您的 functions.php 中,它就会起作用。 也许您还必须转到 wordpress 中的 permalink 设置,然后在添加代码后再次单击 "save changes"。

代码:

add_filter( 'get_pagenum_link', 'wpse_78546_pagenum_link' );

function wpse_78546_pagenum_link( $link )
{
    return preg_replace( '~/(\d+)/?~', '?page=', $link );
}