如何在Jetpack相关文章上添加更多阅读按钮?

时间:2019-11-11 13:25:36

标签: wordpress jetpack

我有一个网站使用Jetpack插件显示我的相关帖子。现在,我想在相关帖子的顶部添加一个更多阅读按钮,以将我重定向到相应的帖子。

我尝试使用Jetpack挂钩在此过滤器发布后添加内容:jetpack_relatedposts_filter_post_context。

function jeherve_related_authors( $context, $post_id ) {
    // Get the author ID.
    $post_author = get_post_field( 'post_author', $post_id );

    // Get the author's display name.
    $author_display_name = get_the_author_meta( 'display_name', 
$post_author );

    // Add the author name after the existing context.
    if ( isset( $author_display_name ) && ! empty( 
$author_display_name ) ) {
        return sprintf(__( '%1$s<span class="jp-relatedposts-post-author">By %2$s</span>', 'my-plugin-slug' ),
        $context,
        esc_html( $author_display_name )
    );
}

    // Final fallback.
    return $context;
}
add_filter( 'jetpack_relatedposts_filter_post_context', 'jeherve_related_authors', 10, 2 );

我希望使用此过滤器在帖子标题下显示按钮。

0 个答案:

没有答案