Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp html excerpt


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.


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


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

Return Values

The excerpt.



$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...'



Change Log

Since: 2.5.0

Source File

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


wp_trim_excerpt(), the_excerpt(), get_the_excerpt()