WordPress replies to comments automatically add @ comments, wordpress comments

Source: Internet
Author: User

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);


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.