I have been searching for a solution to highlight a post if it has a new comment but there is no plugin/forum answer about this.

Basically I have a custom post type listings on a page. I want to add the functionality that if someone (registered users) posts a new comment to any single post, the Post get highlighted on its archive/listing page.

Any help would be highly appreciated.


  • How do you define "new" – Mark Kaplun Apr 6 '16 at 14:19
  • I have no idea on how to define it. Sorry I am not so expert with WordPress – bakar Apr 6 '16 at 14:59
  • For some people something that happened a year ago is new, for other it is old. You have to define what does "new" means for you, otherwise how do you know that your code is actually doing what you wanted it to do? – Mark Kaplun Apr 6 '16 at 15:01
  • understood but I have no idea on how to do that. this is my first experience with this kind of problem so I have little idea on how to do it. – bakar Apr 6 '16 at 15:10
  • Can you please do a code example? – bakar Apr 6 '16 at 15:10

You need to do a couple of things. To find new comments you need to be tracking visitiors. If you're capturing last login time that'd be great. Then you need to edit your template to check your comments before dissplaying the content. Alter you comments query and here and if there's new comment since the last login add a class to the post div element. In your css manipulate the post display any way you like.

Update: I found an easier way. I adapted this code from here You still have to get the last login time yourself using some plugin or other way of getting a timestamp. Maybe set a cookie? I just added an if statement to wp_get_comment_date and if it's newer than the last login flag the comment.

Sorry I can't set up a working sample . . . I just don't have the setup right now.

        $num_comments = get_comments_number(); // get_comments_number returns only a numeric value

        if ( comments_open() ) {
            if ( $num_comments == 0 ) {
                $comments = __('No Comments');
            } elseif ( $num_comments > 1 ) {
                if ( strtotime(get_comment_date( 'yyyy-mm-dd' ) ) > strtotime($get_last_login_tile ) ) {

                    $comments = $num_comments . __('<b> New Comments Since Last Login</b>');

                } else {
                    $comments = $num_comments . __(' Comments');
            } else {
                $comments = __('1 Comment');
            $write_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';
        } else {
            $write_comments =  __('Comments are off for this post.');

| improve this answer | |
  • can you please give a working example? – bakar Apr 6 '16 at 14:57
  • See updated answer - not sure if you get notified of that . . .? – dg4220 Apr 6 '16 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.