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

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:


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

thank you!

share|improve this question
up vote 4 down vote accepted

You can filter 'get_comment_author_IP':

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) ) . '…';

Note this will fail with IPv6 addresses.

share|improve this answer
Brilliaaantttt! Thank you Toscho! – Paweł Skaba Dec 25 '12 at 22:02

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.