get_the_title_rss()
云策文档标注
概述
get_the_title_rss() 函数用于在 RSS 或 Atom 等 feed 中检索当前文章的标题,通过应用 the_title_rss 过滤器允许开发者自定义输出。
关键要点
- 函数返回当前文章的标题字符串,适用于 feed 环境。
- 接受可选参数 $post,可以是文章 ID 或 WP_Post 对象,默认使用全局 $post。
- 内部调用 get_the_title() 获取标题,并通过 apply_filters() 应用 the_title_rss 过滤器进行修改。
- 自 WordPress 6.6.0 版本起添加了 $post 参数,增强灵活性。
代码示例
function get_the_title_rss( $post = 0 ) {
$title = get_the_title( $post );
/**
* Filters the post title for use in a feed.
*
* @since 1.2.0
*
* @param string $title The current post title.
*/
return apply_filters( 'the_title_rss', $title );
}注意事项
- 确保在 feed 上下文中使用,以避免与常规标题函数混淆。
- 使用 the_title_rss 过滤器时,回调函数应接收并返回字符串类型的标题。
原文内容
Retrieves the current post title for the feed.
Parameters
Source
function get_the_title_rss( $post = 0 ) {
$title = get_the_title( $post );
/**
* Filters the post title for use in a feed.
*
* @since 1.2.0
*
* @param string $title The current post title.
*/
return apply_filters( 'the_title_rss', $title );
}
Hooks
- apply_filters( ‘the_title_rss’, string $title )
-
Filters the post title for use in a feed.