Limit Excerpt Length By Characters

How do I limit the Blog excerpt length By Characters instead by words. In my blog using Masonry the excerpts are different lengths and it causes the order to be out of order and I don’t want giant images like st standard setting allows. So setting the excerpt for the blog by character would work a lot better.

Thanks!

Hi There,

Thanks for writing in! By default WordPress limit excerpts by number of words. You may want to try a custom development workaround for this. Try following this guide (https://technumero.com/limit-excerpt-length-wordpress/).

Thanks!

Thanks, I was hoping there was a better way to do it than adding all that in.

Maybe you guys can add a toggle to change the excerpt length between number of words and characters. It would have both options already baked in and would work out of the box!

Thanks for the help!

For anyone that is interested here is what I did to get my excerpt length limited by characters instead of by words.

In my functions.php I added the following:

// Limit except length by # of characters
function get_excerpt( $count ) {
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
  $excerpt = '<p>'.$excerpt.'... <a href="'.$permalink.'" class="more-link">Read More</a></p>';
  return $excerpt;
}

Change the read more link if you want to, remove the class, add your own class… whatever. Then Call the above function by adding this code in your /wp-content/themes/pro/framework/views/global/_content-the-excerpt.php

REPLACE THIS TAG:
<?php the_excerpt(); ?>

WITH THIS TAG: (Change number to desired excerpt length)
<?php echo get_excerpt(111); ?>

Now you are all set! Enjoy your custom character excerpt length!

Thanks for sharing your solution!

You could just add a manual excerpt in Pro, like on attached image. Not exactly on character count but at least you can control the amount of words used.

Hi @yingfuli,

Nice idea and thank you for sharing with us.

Cheers!

Thank you…very helpful. This DOES work BUT

If you use Cornestone for producing/editing the post then the Cornerstone Code shows up in place of the excerpt.
It would be really nice to have a way around this.

Hey There,

You may also add the manual excerpt outside of Cornerstone. Having a manual excerpts will not display Cornerstone codes. Excerpts are optional hand-crafted summaries of your content that can be used in your theme. Learn more about manual excerpts here: https://codex.wordpress.org/Excerpt

Thanks.

Yes you can but by adding a ‘manual’ except in the WP Editor means the the ‘Read More’ Text DOES not appear.

Hello There,

Since WordPress will disregard any contents that is enclosed with a shortcode, auto excerpts is not fully supported yet since all the text contents were enclosed with a Cornerstone formatting shortcode. As of now, there is a pending request to generate an Auto Excerpt when using Cornerstone on a post. Hopefully it will be available soon.

Thank you for your understanding.