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

I'm limiting the number of characters in the title with substr. But even if the title is less than 50 characters, being shown the ellipsis (...). I would not display the ellipsis if the title does not exceed the limit of 50 characters.

$title = substr( $title, 0, 50 ) . "...";

Title of my post ...

(Incorrect: Title less than 50 characters in this case should not display "...")

Title of my post that exceeds 50 characters ...

(Correct: Title longer than 50 characters are cut and accompanied by "...")

share|improve this question
up vote 3 down vote accepted

In the form you have posted this is more of PHP question - you could use strlen() functions to determine length of original title and apply ellipsis conditionally.

However in WP context you should consider using wp_trim_words() since trimming based on words looks tidier and it will take care of appending string of your choice whet cutting.

share|improve this answer
Thanks @Rarst, did not know wp_trim_words, I'm checking ... – BóbGCA Dec 20 '12 at 19:11

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.