fbpx

How to limit excerpt length using characters

Add the following code to the function.php

Option 1

function fix_the_excerpt($text) {
  return str_replace('[...]', '...', $text);
}
add_filter('the_excerpt', 'fix_the_excerpt');

function my_excerpt_length($length) {
  return 10; // Or whatever you want the length to be.
}
add_filter('excerpt_length', 'my_excerpt_length');

Option 2

function get_excerpt($count){
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
  return $excerpt;
}

Note: Paste this code on your template file, change the value 45 to how many characters you want to display.

<?php echo get_excerpt(45); ?>