①这种方法是将@直接写入数据库
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);
②这种方法是只在前端显示,部分主题不能正常显示
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);
将代码添加到主题的 function.php 文件,或者另外写一个插件安装启动即可