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

相关函数:

原创文章,作者:,如若转载,请注明出处:https://ce.771633.xyz/1900.html

Like (0)
Previous 2025年3月8日
Next 2025年3月8日

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注