个性化阅读
专注于IT技术分析

如何自定义主题中的get_the_post_navigation

点击下载

get_the_post_navigation()函数在wp-includes / link-template.php中定义

如何在主题中覆盖它?


#1


get_the_post_navigation不使用任何过滤器, 因此没有简单的方法来修改或覆盖其所有输出。

尽管get_the_post_navigation本身不应用任何过滤器, 但它确实调用了应用过滤器的函数。具体来说就是get_adjacent_post_link:

return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );

连接到该过滤器将使你可以覆盖部分但不是全部输出。 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 );
}

一个简单的解决方案可能是创建你自己的帖子导航功能, 然后用你的主题替换主题中对get_the_post_navigation的所有引用。

赞(0)
未经允许不得转载:srcmini » 如何自定义主题中的get_the_post_navigation

评论 抢沙发

评论前必须登录!