• Resolved jheind

    (@jheind)


    Hi,

    I’m trying to find a way to abbreviate a comment author’s last name. For instance, I want comment author “John Doe” to display as “John D.”. When it comes to writing functions in PHP, I’m in my infancy. Can anyone point me in the right direction?

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter jheind

    (@jheind)

    I figured it out, I think. I found a snippet of code that removed the comment author and then modified it to just manipulate the author’s name. I placed it in my child theme’s functions.php and it did what I wanted it to.

    if ( ! function_exists( 'abbreviate_comment_author' ) ) :
    
        function abbreviate_comment_author( $author ){
            list($author_first, $author_second) = explode(' ',$author, 2);
            $author_second = $author_second[0] . '.';
            $author = $author_first . ' ' . $author_second;
            return $author;
    }
    add_filter( 'get_comment_author', 'abbreviate_comment_author' );
    add_filter( 'comment_author_rss', 'abbreviate_comment_author' );
    
    endif;
Viewing 1 replies (of 1 total)
  • The topic ‘Abbreviate Comment Author’ is closed to new replies.