Jor*_*eFG 2 wordpress wordpress-theming
get_the_post_navigation() 函数定义在里面 wp-includes/link-template.php
如何在主题中覆盖它?
get_the_post_navigation 不使用任何过滤器,因此没有简单的方法来修改或覆盖其所有输出。
虽然get_the_post_navigation本身不应用任何过滤器,但是会调用确实应用过滤器的函数。具体来说get_adjacent_post_link:
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
Run Code Online (Sandbox Code Playgroud)
挂接到该过滤器将使您可以覆盖部分而非全部输出。get_the_post_navigation也使用_navigation_markup不应用任何过滤器的过滤器。输出的那部分不能被覆盖。
您可以要求将过滤器添加到该功能。这将是一个简单的更新,它将使您能够覆盖所有输出。
function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) {
if ( empty( $screen_reader_text ) ) {
$screen_reader_text = __( 'Posts navigation' );
}
$template = '
<nav class="navigation %1$s" role="navigation">
<h2 class="screen-reader-text">%2$s</h2>
<div class="nav-links">%3$s</div>
</nav>';
//Add this line
$template = apply_filters('navigation_markup_template', $template);
return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links );
}
Run Code Online (Sandbox Code Playgroud)
一个更简单的解决方案可能是创建您自己的帖子导航功能,然后get_the_post_navigation用您的功能替换主题中对的所有引用。
| 归档时间: |
|
| 查看次数: |
6086 次 |
| 最近记录: |