0

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 "...")

3

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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