WordPress.org

Forums

[resolved] Limit IP address to few characters (2 posts)

  1. pawciak
    Member
    Posted 2 years ago #

    Hey,

    my client in his template is using <?php comment_author_IP(); ?> to display IP's of comment authors. Recently he came to me with idea of limiting whole number to several characters. Final result should be something simillar to:

    192.168...

    How can i achieve it? I've tried with jquery but without success. It looked like it was not responding to the jquery code..

  2. pawciak
    Member
    Posted 2 years ago #

    To all people looking for solution of this question:

    add_filter( 'get_comment_author_IP', 'wpse_77254_trim_comment_ip' );
    
    function wpse_77254_trim_comment_ip( $ip )
    {
        return implode( '.', array_slice(explode( '.', $ip ), 2) ) . '…';
    }

Topic Closed

This topic has been closed to new replies.

About this Topic