Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 2 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

 
discard

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.