说到这个 WordPress 回复可见的功能,小编早在多年前就尝试过,但是会有一些问题,比如使用多说导致回复后,不能立刻显示内容,所以就取消了这个功能,但是如果是用 WordPress 自带评论模块的话,那么这个功能,可谓是秒回秒可见哈!

下面我们直接说教程吧

这块,我就不推荐大家用什么插件了。完全加入代码即可 OK!

WordPress 主题文件的 functions.php 内加入以下代码:

  1. function reply_to_read($atts, $content=null) {     
  2. "notice" => '<p class="reply-to-read"> 温馨提示: 此处内容需要<a href="#respond" title="评论本文"> 评论本文</a> 后才能查看.</p>'), $atts));     
  3.         $email = null;     
  4. int) wp_get_current_user()->ID;     
  5.         if ($user_ID > 0) {     
  6.               
  7. "[email protected]"  
  8.             if ($email == $admin_email) {     
  9. return $content;     
  10.             }     
  11. else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {     
  12.             $email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);     
  13. else {     
  14.             return $notice;     
  15.         if (empty($email)) {     
  16. return $notice;     
  17.         }     
  18.         $post_id = get_the_ID();     
  19. "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";     
  20.         if ($wpdb->get_results($query)) {     
  21. return do_shortcode($content);     
  22.         } else {     
  23. return $notice;     
  24.         }     
  25.       

将代码里的邮箱替换成我们自己的,添加好后,保存即可!

之后我们在编写文章的时候就可以添加短代码来实现 WordPress 回复可见的功能了!

或者

  1. [@reply notice="自定义的提示信息"] 评论可见的内容 [@/reply]    

大家注意下,小编为了让代码展现出来,在代码里加了 @,大家在使用的时候把 @去掉!functions.php 内的代码仅替换邮箱即可!!!