Custom WordPress Post Titles

Custom WordPress Post Titles

It’s sometimes desirable to set a “maximum title length” so your theme doesn’t break when a user decides to use a ludicrously long post title. So filter the_title().

[code]

function the_titlesmall($echo = true, $before = ”, $after =’…’, $length) {
$title = get_the_title();
if ( strlen($title)>$length ) {
$title = substr( $title, 0, $length );
$title = apply_filters(‘the_titlesmall’, $before . $title . $after, $before, $after);

}else{
echo "string";
}

if($echo == true){
echo $title;
}else{
return $title;
}

}[/code]

And replace “the_title()” with:

[code]

<?php the_titlesmall(true, ”, ‘…’, 10) ?>

[/code]