WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some of my posts' titles have leading words, followed by a colon. I am removing the leading words and the column of every post title in the loop with the following:

  $title = get_the_title();
  $title_array = explode(':', $title);
  $first_word = $title_array[1];
  echo $first_word;

How can I also limit the total length of the remaining title by character count?

share|improve this question
up vote 1 down vote accepted
$title = get_the_title();
$title_array = explode(':', $title);
$first_word = $title_array[1];
$total_length_limit = 100;
echo mb_substr( $first_word, 0, $total_length_limit ) . '...';
share|improve this answer
You really want mb_substr(). – toscho Jun 4 '12 at 18:34
@toscho thanks, fixed. – Eugene Manuilov Jun 4 '12 at 18:36
That worked perfectly. Thank you so much! – Ryan Jun 4 '12 at 18:39
Is there a way that I can append ellipsis to the end? – Ryan Jun 4 '12 at 18:56

I think that if you want to get first word you should set array index to zero: $first_word = $title_array[0];

And regarding your question:

$char_limit = 20;
$out = array_slice($title_array, 1);
$out = join(':',$out);
$out = substr($out, 0, $char_limit).'...';
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.