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 am calling recent comments into my template with


the variable length is specified like this :


how could I write a conditional statement just for comments that exceed the limits of the vairable >180 ?

I was thinking It would be good to have a ... for longer comments and a more link.

share|improve this question
up vote 1 down vote accepted

By using a function to perform that:


that function would look like (in case you're using PHP, part of your code looks from another language):

function recent_comment_text_more($comment_content, $more_href)  {
    if (strlen($comment_content) > 180) {
        $comment_content = substr($comment_content, 0, 177) . sprintf('<a href="%s">... (more)</a>', $more_href);
    return $comment_content;

Good luck!

Multibyte charset safe variant

As pointed out in a comment, e.g. for UTF-8, see mb_internal_encoding() for specifying the encoding to use:

function recent_comment_text_more($comment_content, $more_href)  {
    if (mb_strlen($comment_content) > 180) {
        $comment_content = mb_substr($comment_content, 0, 177) . sprintf('<a href="%s">... (more)</a>', $more_href);
    return $comment_content;
share|improve this answer
Use mb_substr() or multibyte characters may break. – toscho Mar 8 '11 at 6:47
I added a quick edit; the shortened content was being stored in $comment_conent, which would have resulted in this not working correctly. – John P Bloch Apr 8 '11 at 20:24
Thanks for taking care. – hakre Apr 9 '11 at 10:55

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.