On this page
wp_html_excerpt( string $str, int $count, string $more = null ): string
Safely extracts not more than the first $count characters from HTML string.
Description
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.
Parameters
$strstring Required-
String to get the excerpt from.
$countint Required-
Maximum number of characters to take.
$morestring Optional-
What to append if $str needs to be trimmed. Defaults to empty string.
Default:
null
Return
string The excerpt.
Source
File: wp-includes/formatting.php. View all references
function wp_html_excerpt( $str, $count, $more = null ) {
if ( null === $more ) {
$more = '';
}
$str = wp_strip_all_tags( $str, true );
$excerpt = mb_substr( $str, 0, $count );
// Remove part of an entity at the end.
$excerpt = preg_replace( '/&[^;\s]{0,6}$/', '', $excerpt );
if ( $str != $excerpt ) {
$excerpt = trim( $excerpt ) . $more;
}
return $excerpt;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_strip_all_tags() wp-includes/formatting.php | Properly strips all HTML tags including script and style |
Used By
| Used By | Description |
|---|---|
| WP_Customize_Nav_Menus::customize_register() wp-includes/class-wp-customize-nav-menus.php | Adds the customizer settings and controls. |
| get_media_item() wp-admin/includes/media.php | Retrieves HTML form for modifying the image attachment. |
| WP_Comments_List_Table::column_author() wp-admin/includes/class-wp-comments-list-table.php | |
| wp_admin_bar_site_menu() wp-includes/admin-bar.php | Adds the “Site Name” menu. |
| do_trackbacks() wp-includes/comment.php | Performs trackbacks. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_html_excerpt