Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wp_strip_all_tags_breaks($string, $remove_breaks = false) {
- $string = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $string );
- $string = strip_tags($string, '<p>');
- if ( $remove_breaks )
- $string = preg_replace('/[\r\n\t ]+/', ' ', $string);
- return trim( $string );
- }
- function wp_trim_words_breaks( $text, $num_words = 55, $more = null ) {
- if ( null === $more )
- $more = __( '…' );
- $original_text = $text;
- $text = wp_strip_all_tags_breaks( $text );
- /* translators: If your word count is based on single characters (East Asian characters),
- enter 'characters'. Otherwise, enter 'words'. Do not translate into your own language. */
- if ( 'characters' == _x( 'words', 'word count: words or characters?' ) && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
- $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
- preg_match_all( '/./u', $text, $words_array );
- $words_array = array_slice( $words_array[0], 0, $num_words + 1 );
- $sep = '';
- } else {
- $words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
- $sep = ' ';
- }
- if ( count( $words_array ) > $num_words ) {
- array_pop( $words_array );
- $text = implode( $sep, $words_array );
- $text = $text . $more;
- } else {
- $text = implode( $sep, $words_array );
- }
- return apply_filters( 'wp_trim_words', $text, $num_words, $more, $original_text );
- }
- function wp_trim_excerpt_breaks($text = '') {
- $raw_excerpt = $text;
- if ( '' == $text ) {
- $text = get_the_content('');
- $text = strip_shortcodes( $text );
- $text = apply_filters('the_content', $text);
- $text = str_replace(']]>', ']]>', $text);
- $excerpt_length = apply_filters('excerpt_length', 55);
- $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
- $text = wp_trim_words_breaks( $text, $excerpt_length, $excerpt_more );
- }
- return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
- }
- remove_filter('get_the_excerpt', 'wp_trim_excerpt');
- add_filter('get_the_excerpt', 'wp_trim_excerpt_breaks');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement