Themler excerpts length in characters instead of words

Stagger Lee
1818 Posts
Stagger Lee posted this 23 April 2015

For better layout and design, no unpredictable spacing. It overrides your settings in Theme Options.
Excerpts limit by characters. Change 80 to needed limit. Theme functions.php or functions.php in plugin:

function wp_trim_all_excerpt($text) {
$excerpt_length = apply_filters('excerpt_length', 80);
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); //since wp3.3
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wp_trim_all_excerpt');

For better layout and design, no unpredictable spacing. It overrides your settings in Theme Options. Excerpts limit by characters. Change **80** to needed limit. Theme functions.php or functions.php in plugin: function wp_trim_all_excerpt($text) { $excerpt_length = apply_filters('excerpt_length', 80); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3 return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); //since wp3.3 } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'wp_trim_all_excerpt');
Vote to pay developers attention to this features or issue.
4 Comments
Order By: Standard | Newest
Stagger Lee
1818 Posts
Stagger Lee posted this 23 April 2015

Sorry, better one:

function wp_trim_all_excerpt($text) {
$excerpt_length = apply_filters('excerpt_length', 80);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3
return apply_filters('wp_trim_excerpt', $text); //since wp3.3
}
remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wp_trim_all_excerpt');

Sorry, better one: function wp_trim_all_excerpt($text) { $excerpt_length = apply_filters('excerpt_length', 80); $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]'); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); //since wp3.3 return apply_filters('wp_trim_excerpt', $text); //since wp3.3 } remove_filter('get_the_excerpt', 'wp_trim_excerpt'); add_filter('get_the_excerpt', 'wp_trim_all_excerpt');
Support Team
Support Team posted this 23 April 2015

Hello Stager Lee,
thank you for your suggestion, I passed it to our engineers for review and it will be considered as possible improvement.

regards,
Aileen

Hello Stager Lee, thank you for your suggestion, I passed it to our engineers for review and it will be considered as possible improvement. regards, Aileen
Support Team
Support Team posted this 08 May 2015

Hello

Sorry for the delay.
Could you please clarify your request a little.
Do you mean that you want to limit the excerpt length in characters, not words?

Currently the excerpts are limited by words.

Thank you,
Olivia

Hello Sorry for the delay. Could you please clarify your request a little. Do you mean that you want to limit the excerpt length in characters, not words? Currently the excerpts are limited by words. Thank you, Olivia
Stagger Lee
1818 Posts
Stagger Lee posted this 08 May 2015

Yes, character limit, not words limit. It is the same amount of work for PHP server, so better to limit by characters. For more uniform layout.

Any better, put this code in custom templates when calling excerpt. So we can have different excerpt lenghts. Just one new option in Themler where we put number.

One column posts listing can have many characters, but doesnt look good on posts in 2-3 columns.

Any option is welcome.

Yes, character limit, not words limit. It is the same amount of work for PHP server, so better to limit by characters. For more uniform layout. Any better, put this code in custom templates when calling excerpt. So we can have different excerpt lenghts. Just one new option in Themler where we put number. One column posts listing can have many characters, but doesnt look good on posts in 2-3 columns. Any option is welcome.
You must log in or register to leave comments