Phill Collins
Phill Collins

Reputation: 183

Wordpress truncating titles

I have this working... but.

<?php
$thetitle = $post->post_title; /* or you can use get_the_title() */
$getlength = mb_strlen($thetitle);
$thelength = 25;
echo mb_substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>

Just say the title is "Hey, how are you" and it truncates it after "Hey, ".

There is a space I want to eliminate after the comma and before the end quote.

Is there a way to do this? Otherwise the title looks like:

Hey, ...

Instead of:

Hey,...

Thanks

Upvotes: 0

Views: 1193

Answers (1)

Sujit Agarwal
Sujit Agarwal

Reputation: 12508

echo trim(mb_substr($thetitle, 0, $thelength));

you just need to trim the white spaces.

Upvotes: 2

Related Questions