WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Character limit on comment author (8 posts)

  1. conditionkill
    Member
    Posted 5 years ago #

    How can I limit name length on comment authors?

  2. conditionkill
    Member
    Posted 5 years ago #

    Here's how it looks when someone posts with a really long name..
    Messes up the whole site.. :(
    http://img217.imageshack.us/img217/8884/20090219200735ao4.png

  3. tomontoast
    Member
    Posted 5 years ago #

    This should do the trick: in either your themes header.php or functions.php add the following piece of code

    add_filter('get_comment_author',create_function('$author','return substr($author,0,40)');)

    The 40 can be changed to change the maximum limit of the authors name.

    I haven't tested this myself but it should work!

  4. conditionkill
    Member
    Posted 5 years ago #

    It works, awesome! Thx alot ;D

    Btw if anyone wanna copy this code there was a small typo, the semicolon in the end was misplaced and the code should be
    add_filter('get_comment_author', create_function('$author','return substr($author,0,25);'))
    If you want it to work :)

  5. tomontoast
    Member
    Posted 5 years ago #

    Sorry about the typo! It was written in a bit of a rush but I'm glad it works!

  6. chanel
    Member
    Posted 5 years ago #

    How does a novice like myself actually add that code? Do I do it like this?

    <?php add_filter('get_comment_author', create_function('$author','return substr($author,0,25);'))>


    ?????????????

  7. jcow
    Member
    Posted 5 years ago #

    Do it like this:

    <?php add_filter('get_comment_author', create_function('$author','return substr($author,0,25);')); ?>

  8. chanel
    Member
    Posted 5 years ago #

    Thank you jcow. I will try that and return with the results.

Topic Closed

This topic has been closed to new replies.

About this Topic