如何在阅读更多内容之前将wordpress发布网址显示到摘要中

时间:2019-05-15 13:16:43

标签: wordpress custom-wordpress-pages

我有兴趣知道如何在READ MORE按钮之前将文章永久链接添加为TEXT来摘录。 例如我的帖子永久链接为www.abc.com/how-to-earn-money,标题为“如何赚钱”。

现在描述下面的问题。 左边的特色图片还可以。帖子标题将显示为“如何赚钱”。帖子摘要将显示为“等等”,并带有“读取更多”按钮

现在,我只想在“摘要”按钮之前的帖子摘录中添加www.abc.com(不是完整的URL)。你能告诉我怎么做吗?

我不是要深入了解的技术人员,所以我只想添加一些自定义php代码来添加帖子永久链接。

function replace_excerpt($content) {
       return str_replace('[...]',
               '<div class="more-link"><a href="'. get_permalink() .'">Continue Reading</a></div>',
               $content
       );
}
add_filter('the_excerpt', 'replace_excerpt');

这是用url替换摘录文本,但这不起作用,我想保留我所解释的摘录。

1 个答案:

答案 0 :(得分:0)

您可以使用过滤器来修改摘录,尝试将过滤器名称更改为 get_the_excerpt

https://codex.wordpress.org/Plugin_API/Filter_Reference/get_the_excerpt

function modify_excerpt( $excerpt ) {
    global $post;

    $url = get_post_meta( $post->ID, 'custom_url', true );
    $excerpt .= str_replace( $excerpt, '[...]', '<br/>' . $url );

    return $excerpt;
}
add_filter( 'get_the_excerpt', 'modify_excerpt' );
相关问题