WordPress replies to comments automatically add @ comments, wordpress comments
Some netizens left a message asking me how to implement this @ nickname reply? For example:
In fact, I also saw a lot of blogs with such features, but I reviewed and replied to comments in the background. I did not pay attention to the comment column several times: reply ***, I thought it was a message to me, so I replied some inexplicable content and made many jokes. For this reason, I recently added this function to the Honghu entertainment circle. When replying to a comments, I added a @ comments to the front of the message, so that I can better identify who to reply. You may already have relevant tutorials online, but here I will share my implementation methods and add the following code to the current topic pluggable. php:
function ludou_comment_add_at( $commentdata ) { if( $commentdata['comment_parent'] > 0) { $commentdata['comment_content'] = '@<a href="#comment-' . $commentdata['comment_parent'] . '">'.get_comment_author( $commentdata['comment_parent'] ) . '</a> ' . $commentdata['comment_content']; } return $commentdata;}add_action( 'preprocess_comment' , 'ludou_comment_add_at', 20);
The above Code directly writes @ information to the database. As instructed by bigfa, if you do not want to write @ reviewer to the database, you can use the following code:
function ludou_comment_add_at( $comment_text, $comment = '') { if( $comment->comment_parent > 0) { $comment_text = '@<a href="#comment-' . $comment->comment_parent . '">'.get_comment_author( $comment->comment_parent ) . '</a> ' . $comment_text; } return $comment_text;}add_filter( 'comment_text' , 'ludou_comment_add_at', 20, 2);