如果您想用指向文章的永久链接替换摘录中的省略号 […],这将非常有用。
functions.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');
非常有用,已尝试并测试,谢谢。
赢了!
有用的代码片段,谢谢!
您在哪里放置此函数?
我一直使用
function new_excerpt_more($more) {
global $post;
return ‘… a class=”more-link” href=”‘. get_permalink($post->ID) . ‘”>’ . ‘阅读更多 »’ . ‘/a’;
}
add_filter(‘excerpt_more’, ‘new_excerpt_more’);
但是它仍然在文章末尾显示“…”。
这干净多了。谢谢!
因为你的代码中有“…” :)
你好,
感谢你所有的技巧,你为我们节省了大量时间!
使用这个技巧对 SEO 有什么影响吗?
此致,
嘿,伙计,
非常感谢你分享这个,但我遇到一个小问题…
我有一个网站(www.laptopshelp.com),在主页上,文本到“阅读更多…”之间有很大的填充。
有办法解决这个问题吗?如果有,怎么做?
此致,Altin
这在我的主题中不起作用,直到我写了这个
<?php function replace_excerpt($content) {
return str_replace('[…]', '... ', $content );
}?>
因为 &hellip 是适当的 HTML 实体
谢谢!上面的代码片段和 &hellip 的组合有效。为我节省了时间,谢谢 Alex。
还要感谢 CSS-Tricks,这个网站经常非常宝贵。
谢谢 Alex,这对我有用。
我已更新此代码以与 HTML 实体一起使用,但仍保持向后兼容。 查看 Gist。