0

I'd like your help to fix something that's driving me crazy. In my front-page.php I have modified my excerpts length with this code:

//* Modify the length of post excerpts
add_filter( 'excerpt_length', 'rtny_excerpt_length' );
function rtny_excerpt_length( $length ) {
    return 60; // pull first 60 words
}

The problem is that if I limit the length with words (as some words are longer than other), the result in the web I'm creating is not looking so well this is how it looks like .

I think if I could limit the number of characters or lines instead of words I could get a better look with all meta aligned. But I'm really new in coding so I pleaaase really need help. I hope my English is not so bad and :)

Thank you in advance!

Macapav
  • 1
  • 1
  • 4
    Possible duplicate of [How to Truncate a string in PHP to the word closest to a certain number of characters?](http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara) – Ali Hamze Nov 11 '15 at 22:23
  • can also be done in the querry –  Nov 11 '15 at 22:33

1 Answers1

0

Here is a nice excerpt function that takes tags into account:

function get_excerpt(){
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, 40);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
return $excerpt;
}
Dracony
  • 842
  • 6
  • 15