Wordpress分页,更改目标

kgqe7b3p  于 2023-01-12  发布在  WordPress
关注(0)|答案(1)|浏览(117)

是否有可能更改wordpress中的分页:https://schoblatt.de/page/2至:https://schoblatt.de/page/2#content
我找到:_after_page_number并测试此:

<?php
add_action( 'init', 'my_custom_page_word' );
function my_custom_page_word() {
  global $wp_rewrite;  // Get the global wordpress rewrite-rules/settings

  // Change the pagination property which sets the wordpress pagination slug.
  $wp_rewrite->pagination_after_page_number = "#Content";  //where new-slug is the slug you want to use ;)
} ?>

但它不工作,我没有经验的php。

eyh26e7m

eyh26e7m1#

如果您使用paginate_links函数创建分页,它具有add_fragment参数,该参数是"附加到每个链接的字符串"。
示例:

$args = [
    'add_fragment' => '#content',
];

?>
<nav class="pagination"><?php echo paginate_links( $args ); ?></nav>
<?php

相关问题