Title: Author comments hook
Last modified: January 12, 2019

---

# Author comments hook

 *  Resolved [indeedably](https://wordpress.org/support/users/indeedably/)
 * (@indeedably)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/author-comments-hook/)
 * Hi Anders. Thanks for creating and maintaining the beautiful Hitchcock theme.
 * Feature request: Add a CSS class hook to allow styling of comments made by post
   authors, distinguishing them from comments made by readers.
 * In functions.php you currently have:
 *     ```
       <h4 class="comment-title">
       	<?php echo get_comment_author_link(); ?>
       	<span><a class="comment-date-link" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>" title="<?php echo get_comment_date() . ' at ' . get_comment_time(); ?>"><?php echo get_comment_date( get_option( 'date_format' ) ); ?></a>
       	<?php
       	if ( $post == get_post( $post->ID ) ) {
       		if ( $comment->user_id === $post->post_author )
       		echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
       	}
       	?>
       	</span>
       </h4>
       ```
   
 * There is probably a more elegant way to achieve it, but the replicating the if
   block used to output the POST AUTHOR text gets the job done. A simple addition
   along the lines of the following would allow users to style the H4 when it is
   the author replying.
 *     ```
       <h4 class="comment-title<?php
       	if ( $post == get_post( $post->ID ) ) {
       		if ( $comment->user_id === $post->post_author )
       		echo ' author';
       	}
       	?>">
       	<?php echo get_comment_author_link(); ?>
       	<span><a class="comment-date-link" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>" title="<?php echo get_comment_date() . ' at ' . get_comment_time(); ?>"><?php echo get_comment_date( get_option( 'date_format' ) ); ?></a>
       	<?php
       	if ( $post == get_post( $post->ID ) ) {
       		if ( $comment->user_id === $post->post_author )
       		echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
       	}
       	?>
       	</span>
       </h4>
       ```
   
 * The problem with trying to use the existing byuser hook is that while it successfully
   styles the first comment by the post author, all subsequent comments in the thread(
   regardless of whether or not they are made by the post author) are similarly 
   styled.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Theme Author [Anders Norén](https://wordpress.org/support/users/anlino/)
 * (@anlino)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/author-comments-hook/#post-11080819)
 * Hi [@indeedably](https://wordpress.org/support/users/indeedably/),
 * You can solve this by using the following targeting in CSS:
 *     ```
       .bypostauthor > div.comment .comment-title {
           color: red;
       }
       ```
   
 * That will only hit the comment posted by the post author.
 * — Anders
 *  Thread Starter [indeedably](https://wordpress.org/support/users/indeedably/)
 * (@indeedably)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/author-comments-hook/#post-11080975)
 * Thanks Anders, that works perfectly.
 * Given this is possible, shouldn’t the php code:
 *     ```
       <?php
       if ( $post == get_post( $post->ID ) ) {
       	if ( $comment->user_id === $post->post_author )
       	echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
       }
       ?>
       ```
   
 * Be some CSS code like the following?
 *     ```
       .bypostauthor > div.comment .comment-title::after { 
         content: " &mdash; Post Author";
       }
       ```
   
 * That would allow for the “_ – post author_” text to be altered/removed without
   needing to modify the php code.
 * Thanks again 🙂
 *  Theme Author [Anders Norén](https://wordpress.org/support/users/anlino/)
 * (@anlino)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/author-comments-hook/#post-11080988)
 * [@indeedably](https://wordpress.org/support/users/indeedably/) No problem! Theme
   strings need to be included in the PHP code, using internationalization functions,
   for them to be translateable through translate.wordpress.org.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Author comments hook’ is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/hitchcock/2.2.1/screenshot.jpg)
 * Hitchcock
 * [Support Threads](https://wordpress.org/support/theme/hitchcock/)
 * [Active Topics](https://wordpress.org/support/theme/hitchcock/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/hitchcock/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/hitchcock/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Anders Norén](https://wordpress.org/support/users/anlino/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/author-comments-hook/#post-11080988)
 * Status: resolved