WordPress生成摘要函数:wp_trim_excerpt

WordPress函数wp_trim_excerpt生成长度为55字符的文章摘要。

wp_trim_excerpt( string $text = '', WP_Post|object|int $post = null )

函数参数

$text

字符串

摘要文字,如果为空,则从文章内容中提取。

$post

整数或WP_Post对象

文章的ID或对象

函数返回值

返回长度为55字符的文章摘要,摘要长度可以通过excerpt_length钩子过滤。

function bzg_excerpt_length($excerpt_length) {
	return 150;
}
add_filter('excerpt_length', 'bzg_excerpt_length', 10, 1);

函数使用示例

echo '摘要:' . wp_trim_excerpt('', 3703);

扩展阅读

wp_trim_excerpt()函数位于:wp-includes/formatting.php

相关函数:

阿里云