$max_characters ) { // Truncate $text to $max_characters + 1. $text = mb_substr( $text, 0, $max_characters + 1 ); // Truncate to the last space in the truncated string. $text_trim = trim( mb_substr( $text, 0, mb_strrpos( $text, ' ' ) ) ); $text = empty( $text_trim ) ? $text : $text_trim; } return $text; } /** * Return content stripped down and limited content. * * Strips out tags and shortcodes, limits the output to `$max_char` characters, and appends an ellipsis and more link to the end. * * @since 1.0.0 * * @param int $max_characters The maximum number of characters to return. * @param string $more_link_text Optional. Text of the more link. Default is "(more...)". * @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false. * @return string Limited content. */ function get_the_content_limit( $max_characters, $more_link_text = '(more...)', $stripteaser = false ) { $content = get_the_content( '', $stripteaser ); // Strip tags and shortcodes so the content truncation count is done correctly. $content = strip_tags( strip_shortcodes( $content ), apply_filters( 'get_the_content_limit_allowedtags', '