Skip to content

Instantly share code, notes, and snippets.

@whalesalad
Created November 24, 2009 12:04
Show Gist options
  • Select an option

  • Save whalesalad/241823 to your computer and use it in GitHub Desktop.

Select an option

Save whalesalad/241823 to your computer and use it in GitHub Desktop.
function tasty_title($length = 35){
$title = get_the_title();
// Shorten
if (strlen($title) > $length) {
$suffix = '...';
$short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($title)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
$desc .= $suffix;
$title = $desc;
}
if (strlen($title) == 0)
$title = "Untitled";
echo $title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment