get_wp_title_rss()
云策文档标注
概述
get_wp_title_rss() 函数用于获取博客标题作为 RSS 源标题。它通过 apply_filters 钩子允许过滤标题,并已弃用 $deprecated 参数。
关键要点
- 函数返回当前文档标题,适用于 RSS 源标题。
- 参数 $deprecated 已弃用,自 4.4.0 版本起建议使用 document_title_separator 过滤器替代。
- 内部使用 wp_get_document_title() 获取标题,并通过 apply_filters('get_wp_title_rss') 钩子进行过滤。
- 相关函数包括 wp_get_document_title()、__()、_deprecated_argument() 和 apply_filters()。
代码示例
function get_wp_title_rss( $deprecated = '–' ) {
if ( '–' !== $deprecated ) {
/* translators: %s: 'document_title_separator' filter name. */
_deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), 'document_title_separator' ) );
}
/**
* Filters the blog title for use as the feed title.
*
* @since 2.2.0
* @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`.
*
* @param string $title The current blog title.
* @param string $deprecated Unused.
*/
return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated );
}注意事项
- 自 WordPress 4.4.0 起,$deprecated 参数已弃用,使用时应避免传递非默认值。
- 可通过 get_wp_title_rss 过滤器自定义返回的标题。
原文内容
Retrieves the blog title for the feed title.
Parameters
$deprecatedstringrequired-
Unused.
Source
function get_wp_title_rss( $deprecated = '–' ) {
if ( '–' !== $deprecated ) {
/* translators: %s: 'document_title_separator' filter name. */
_deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) );
}
/**
* Filters the blog title for use as the feed title.
*
* @since 2.2.0
* @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`.
*
* @param string $title The current blog title.
* @param string $deprecated Unused.
*/
return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated );
}
Hooks
- apply_filters( ‘get_wp_title_rss’, string $title, string $deprecated )
-
Filters the blog title for use as the feed title.