WordPress.org

Ready to get started?Download WordPress

Codex

Function Reference/wp html excerpt

Contents

Description

Safely extracts not more than the first $count characters from an HTML string.

This function performs UTF-8-, tags- and entities-safe excerpt extraction. Entities inside will not be counted as one character. For example & will be counted as 4, < as 3, etc.

Usage

<?php wp_html_excerpt$str$count$more ); ?>

Parameters

$str
(string) (required) String to get the excerpt from.
Default: None
$count
(integer) (required) Maximum number of characters to take.
Default: None
$more
(string) (optional) What to append if $str needs to be trimmed. If null, it defaults to an empty string.
Default: null

Return Values

(string) 
The excerpt.

Examples

<?php

$str = 'There are lots &amp; <strong>lots</strong> of usages for this function. I know you can think of some! (lots more text here)';

echo wp_html_excerpt( $str, 50 );

// Output: 'There are lots &amp; lots of usages for this funct'

// Using the $more parameter:
echo wp_html_excerpt( $str, 50, '...' );

// Output: 'There are lots &amp; lots of usages for this funct...'

?>

Notes

Change Log

Since: 2.5.0

Source File

wp_html_excerpt() is located in wp-includes/formatting.php

Related

wp_trim_excerpt(), the_excerpt(), get_the_excerpt()