wordpress收费下载资源主题
wordpress付费下载资源插件

WordPress hook钩子get_the_excerpt的用法详解

WordPress的get_the_excerpt钩子是在获取文章摘要时调用的一个函数。它返回文章的摘要内容。

使用该钩子可以对文章摘要进行自定义修改或增加额外的功能。

下面是get_the_excerpt钩子的使用示例:

1. 修改文章摘要的长度:

function custom_excerpt_length($length) {
return 20; // 设置摘要长度为20个字
}
add_filter('excerpt_length', 'custom_excerpt_length');

2. 在文章摘要后追加“继续阅读”链接:

function custom_excerpt_more($more) {
return '... 继续阅读 »';
}
add_filter('excerpt_more', 'custom_excerpt_more');

3. 自定义文章摘要的样式:

function custom_excerpt_style($excerpt) {
return '

' . $excerpt . '

';
}
add_filter('get_the_excerpt', 'custom_excerpt_style');

4. 获取文章摘要的同时显示缩略图(需要安装并启用插件Featured Image in RSS Feed):

function custom_excerpt_with_thumbnail($excerpt) {
if (has_post_thumbnail()) {
$thumbnail = get_the_post_thumbnail(get_the_ID(), 'thumbnail');
$excerpt = $thumbnail . $excerpt;
}
return $excerpt;
}
add_filter('get_the_excerpt', 'custom_excerpt_with_thumbnail');

这些只是get_the_excerpt钩子的一些用法示例,你可以根据具体需求进行自定义修改。

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情