Walker News

Enable Gravatar In WordPress Comment And Pingback

The new WalkerNews WordPress theme is Gravatar enabled.

As long as you leave a comment with email that used to create the Gravatar, WalkerNews.net automatically fetch your Avatar and show it out.

Turn on or display Gravatar in WordPress comments and pingbacks
Display Gravatar in WordPress theme.

It’s not difficult to enable or display the Gravatar in WordPress theme. WordPress community is always not short of plugins or PHP snippet for extension.

And for WalkerNews.net theme, the PHP snippet is hack to display Gravatar for both site author’s comments and pingbacks (also display Avatar of readers).

How to enable Gravatar in WordPress theme comments?
Display Gravatar in site author’s pingback.
Here is the PHP snippet (just a simple hack to the published code):
  1. Edit the comments.php (exists in most standard WordPress theme)
  2. Locate the comment_text() function (normally called only once in standard comments.php template file)
  3. Remark or comment out the line with comment_text() function
  4. Paste the following PHP snippet right after the remarked comment_text() line (the blue colour PHP codes should be changed to suit your site accordingly; the red colour lines is the one commented out just now.
    <?php
    
       $authurl = substr($comment->comment_author_url,7,18);
    
       if ( !empty( $comment->comment_author_email ) ) {
    
          $md5 = md5( $comment->comment_author_email );
    
          $default = urlencode( 'http://blog.gravatar.com/wp-content/themes/vip/gravatar/logo.gif' );
    
          echo "<img style='float: right; margin-left: 10px;' src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&amp;size=80&amp;default=$default' alt='Gravatar' />";
    
       } elseif ($authurl == 'www.walkernews.net') {
    
          $md5 = md5("email@walkernews.net");
    
          $default = urlencode( 'http://blog.gravatar.com/wp-content/themes/vip/gravatar/logo.gif' );
    
          echo "<img style='float: right; margin-left: 10px;' src='http://www.gravatar.com/avatar.php?gravatar_id=$md5&amp;size=80&amp;default=$default' alt='Gravatar' />";
    
       }
    
       comment_text();
    
    ?>
  5. Save the changes made in comments.php template file.

Now onwards, you’ll see Gravatar appears at the right-hand side (as per CSS style in the PHP snippet) on your own comments and pingbacks (in your own blog).

Personally, I thought to have Gravatar displayed will be useful to highlight site author’s comments and pingbacks.

Custom Search

  1. Classy Black Wordpress Theme By AskGraphics – Walker News 08-11-07@22:06

    [...] Hack : I would prefer to remove the graphic in header, add in WordPress 2.3 Tag Cloud and Post Tag, enable Gravatar feature, using brighter font color and justify text-alignment for the post [...]

  2. evathiste 03-03-08@22:56

    Hello there.
    Just found your site. Great job!
    I like it much.

  3. vetdaspdast 11-02-09@11:37

    exciting and educational, but would participate in something more on this topic?

2014  •  Privacy Policy