function wp_html_excerpt( $str, $count ) {}

Safely extracts not more than the first $count characters from html string.
UTF-8, tags and entities safe prefix extraction. Entities inside will *NOT* be counted as one character. For example & will be counted as 4, < as 3, etc.


  • integer $str: String to get the excerpt from.
  • integer $count: Maximum number of characters to take.

Return values

returns:The excerpt.

Source code

function wp_html_excerpt( $str, $count ) {

	$str = wp_strip_all_tags( $str, true );

	$str = mb_substr( $str, 0, $count );

	// remove part of an entity at the end

	$str = preg_replace( '/&[^;\s]{0,6}$/', '', $str );

	return $str;



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: