
I was given the task of figuring out how to show the “…” after a post title in a preview of the blog page. Many of the things I found were for limiting a user to x number of characters but I didn’t want that. I had to keep my characters to about 60 or less.
Here is what I ended up doing.
Step One: Open the functions.php file and insert this code:
function max_title_length( $title ) {
$max = 65;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). ” …”;
} else {
return $title;
}
}
$max = 65;
if( strlen( $title ) > $max ) {
return substr( $title, 0, $max ). ” …”;
} else {
return $title;
}
}
Step Two: Add this content to your post loop.
<?php add_filter( ‘the_title’, ‘max_title_length’); the_title(); ?>
Thats it!