the_excerpt_embed()
云策文档标注
概述
the_excerpt_embed() 函数用于在嵌入模板中显示文章摘要,专为在 The Loop 中使用而设计。
关键要点
- 函数调用 get_the_excerpt() 获取文章摘要,并通过 apply_filters() 应用 'the_excerpt_embed' 过滤器。
- 提供 'the_excerpt_embed' 过滤器钩子,允许开发者自定义嵌入模板中的摘要输出。
- 相关函数包括 get_the_excerpt() 和 apply_filters(),用于检索摘要和处理过滤器。
代码示例
function the_excerpt_embed() {
$output = get_the_excerpt();
/**
* Filters the post excerpt for the embed template.
*
* @since 4.4.0
*
* @param string $output The current post excerpt.
*/
echo apply_filters( 'the_excerpt_embed', $output );
}注意事项
- 此函数自 WordPress 4.4.0 版本引入,使用时需确保版本兼容性。
- 应在 The Loop 中调用,以确保正确获取当前文章的摘要。
原文内容
Displays the post excerpt for the embed template.
Description
Intended to be used in ‘The Loop’.
Source
function the_excerpt_embed() {
$output = get_the_excerpt();
/**
* Filters the post excerpt for the embed template.
*
* @since 4.4.0
*
* @param string $output The current post excerpt.
*/
echo apply_filters( 'the_excerpt_embed', $output );
}
Hooks
- apply_filters( ‘the_excerpt_embed’, string $output )
-
Filters the post excerpt for the embed template.
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |