Tutorial: How to display short blog title in WordPress

As was recently pointed out to me by Andy in the comments, this post was quite out of date. I was fairly new to WordPress and had found a hacked way to modify the core of WordPress to return a short version of wp_title(); — but this is a method far from necessary and will always get removed when you update WordPress.

I opted to delete the out-of-date method, so that you only get the stuff that makes sense!

There is a simple script you can use to implement a short blog title without modifying the base WordPress code. Open up your functions.php file within your theme and add the following:

function short_title() {
 $title = get_the_title();
 $count = strlen($title);
 if ($count >= 25) {
 $title = substr($title, 0, 25);
 $title .= '...';
 }
 echo $title;
}

You can now reference short_title(); anywhere within the loop and call your short title. You can adjust how long your title is by changing the number “25″ to however many characters you want.

Tags: , ,

6 awesome comments have been left on this post.

  1. July 14, 2009 at 1:18 am

    what an informative posts, I will bookmark this site to digg. Regards, Reader.

  2. July 23, 2009 at 1:54 pm

    This brings me to an idea:…

    EliasTiez
  3. July 24, 2009 at 4:59 am

    Great post! I’ll subscribe right now wth my feedreader software!

    LnddMiles
  4. July 13, 2010 at 12:05 am

    try to change it to work with 3.0, brgs

    andy
  5. July 13, 2010 at 1:11 am

    hmmm, this post script can’t show the call code :))))))))))))))))
    ok, I try this way – all from bottom must be in one sequence, in one line

    start_code__end_code

    end delete start_code_ and _end_code

    andy
  6. July 13, 2010 at 1:12 am

    another way

    here must be the php opener

    wp_title(”, true, ”, true);

    and here you must close the php code

    andy

Leave a Reply