For some reason, a lot of people seem to be using extremely long post titles. I am a firm believer in making a title as precise as possible to make it easier on people who are trying to actually find your article. Sure, I guess you can throw in as many keywords as you want in hopes that you might get more from Google, but I doubt that will really do anything for your site’s SEO.

In case you are one of those people who feel the need for extremely long post titles and you want to display them in places where they might not fit, here is a quick piece of code that you can add to your functions.php file.

function short_title($after = '', $length) {
	$mytitle = explode(' ', get_the_title(), $length);
	if (count($mytitle)>=$length) {
		array_pop($mytitle);
		$mytitle = implode(" ",$mytitle). $after;
	} else {
		$mytitle = implode(" ",$mytitle);
	}
	return $mytitle;
}

You can call the function like so:

<?php 
// short_title($after, $length)
echo short_title('...', 10); 
?>

The above code will truncate your title at 10 words and add a trailing ellipsis.