Here is how to setup a custom WordPress excerpt function with the following criteria:

  • This will allow you to limit the amount of characters displayed in the excerpt
  • While limiting the number of characters displayed this will prevent the last word from getting cut off.  In other words it will limit the number of characters but fully display the last word
  • Show “read more” or “…” text after the excerpt
  • If there is NOT more to read – meaning if the post length is shorter than the number of designated characters in the excerpt – it will not show a “…” or “read more” text

Here is how this is done.  First, put the following snippet of code in your functions.php file:

function get_excerpt($count) {
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  if ( strlen( $excerpt ) <= $count ) {
    return $excerpt;  }
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
  $excerpt .= '...';
  return $excerpt;

The section above that says:


is where you would put your html to make it says “Read more” or whatever you want.

Next, you can call the excerpt in your theme file using this code:

The number “400” is your character limit designation. So if you want the excerpt to show only 50 characters change that number to “50”.

Leave a Reply

Get in Touch

Please fill out the form below and we will get back to you ASAP

  • This field is for validation purposes and should be left unchanged.