If you have a static frontpage or if you are using wordpress as a CMS, you may like this feature. This hack will limit or hide overflowing text in your page.
Here is how you can Limit Post title characters in wordpress. Open your functions.php file from your theme folder and add the following code.
<?php
function the_title2($before = '', $after = '', $echo = true, $length = false) {
$title = get_the_title();
if ( $length && is_numeric($length) ) {
$title = substr( $title, 0, $length );
}
if ( strlen($title)> 0 ) {
$title = apply_filters('the_title2', $before . $title . $after, $before, $after);
if ( $echo )
echo $title;
else
return $title;
}
}
?>
To implement it on your blog post title look for this code below in your index.php, home.php, the single.php or where you want to limit the post title displayed:
<?php the_title(); ?>
Replace that with:
<?php the_title2('', '...', true, '30') ?>
The number 30 is the number of characters to be displayed on the blog post title. You can increase or decrease it as you like.
If you enjoyed this post, please share!