First, I am sure you can find a plug-in for Wordpress that performs this functionality as well, but I did not want to make this a “plug-in” per se, so I figured I would just give you a working snippet of code and allow you to take it from there. I needed to shorten the titles for a project I have been working on and I figured that you might find this useful as well. It is short, sweet and to the point so give it a try.

Next, I am assuming your Wordpress theme has a functions.php file within the theme directory, if not.. make one. It’s pretty simple, just make a new file within your wp-content/themes/ / directive with the file name “functions.php”

In that file, put the code:

function short_title($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('short_title', $before . $title . $after, $before, $after);

if ( $echo )

echo $title;

else

return $title;

}

}

?>

After you place this in your functions.php file, it makes the function “short_title();” available for use within your theme. Then, whenever you need the shorter version of your title, limited to a specific number of characters, you call

The variables are short_title(‘before’, ‘after’, true, ‘character limit’) the “true” is to echo it out, so you can leave it alone. If you wanted to have your titles have say… ** in front of them and ** after them, you could do short_title(‘**’,'**’,true, ‘41′); where 41 would be the number of characters before the **

Short, sweet, and to the point. Just a random something from my brain today.