腾讯云服务器优惠活动华纳云香港服务器

如何在WordPress后台回复评论处添加表情

WordPress主题推荐

我每天都喜欢登录到WordPress后台,如果有评论需要回复时就直接在后台回复,而不想打开文章页再回复,但是这有一个弊端,那就是在后台评论时,无法使用表情,感觉非常不好。所以今天就分享一下如何在WordPress后台回复评论处添加表情功能。

如何在WordPress后台回复评论处添加表情-第1张-boke112百科(boke112.com)

具体的操作步骤如下:

1、下载《如何替换WordPress的默认评论表情?》这篇文章中的smiley.php文件(PS:或自己所使用主题中的smiley.php)。

2、在smiley.php文件中找到下列代码:

  1. if (document.getElementById(‘comment’) && document.getElementById(‘comment’).type == ‘textarea’) {myField = document.getElementById(‘comment’);

替换为(或直接注释掉以上代码):

  1. if (document.getElementById(‘replycontent’) && document.getElementById(‘replycontent’).type == ‘textarea’) {myField = document.getElementById(‘replycontent’);

3、将修改后的smiley.php放入/wp-admin/includes/文件夹中。

4、打开/wp-admin/includes/template.php文件,在

  1. <?php _e( ‘Reply to Comment’ ); ?>

后面(448行左右)添加如下代码,并保存覆盖。

  1. <?php include_once“smiley.php” ?>

至此,已经成功实现WordPress后台回复评论处添加表情功能了,不过美中不足的就是有两个缺点:

1、在后台首页进行回复评论还是无法使用表情,必须点击左侧的“评论”,在出现的评论中回复才能使用表情。

2、WordPress升级后,必须重新更新/wp-admin/includes/template.php文件。

不过这些缺点不影响操作,不介意的可以折腾折腾!

以上代码来源于:Gimhoy

第二种方法是直接集成到主题中,只需要把下边的代码添加到当前主题的 functions.php最后一个?>前面即可。

  1. /**
  2.     *WordPress 后台回复评论插入表情
  3.     *http://www.endskin.com/admin-smiley.html
  4. */
  5. function Bing_ajax_smiley_scripts(){
  6.     echo ‘<script type=“text/javascript”>function grin(e){var t;e=” “+e+” “;if(!document.getElementById(“replycontent”)||document.getElementById(“replycontent”).type!=“textarea”)return!1;t=document.getElementById(“replycontent”);if(document.selection)t.focus(),sel=document.selection.createRange(),sel.text=e,t.focus();else if(t.selectionStart||t.selectionStart==“0”){var n=t.selectionStart,r=t.selectionEnd,i=r;t.value=t.value.substring(0,n)+e+t.value.substring(r,t.value.length),i+=e.length,t.focus(),t.selectionStart=i,t.selectionEnd=i}else t.value+=e,t.focus()}jQuery(document).ready(function(e){var t=“”;e(“#comments-form”).length&&e.get(ajaxurl,{action:“ajax_data_smiley”},function(n){t=n,e(“#qt_replycontent_toolbar input:last”).after(“<br>”+t)})})</script>’;
  7. }
  8. add_action( ‘admin_head’, ‘Bing_ajax_smiley_scripts’ );
  9. //Ajax 获取表情
  10. function Bing_ajax_data_smiley(){
  11.     $site_url = site_url();
  12.     foreacharray_unique( (array$GLOBALS[‘wpsmiliestrans’] ) as $key => $value ){
  13.         $src_url = apply_filters( ‘smilies_src’, includes_url( ‘images/smilies/’ . $value ), $value$site_url );
  14.         echo ‘ <a href=“javascript:grin(\” . $key . ‘\’)”><img src=“‘ . $src_url . ‘” alt=“‘ . $key . ‘” /></a> ‘;
  15.     }
  16.     die;
  17. }
  18. add_action( ‘wp_ajax_nopriv_ajax_data_smiley’, ‘Bing_ajax_data_smiley’ );
  19. add_action( ‘wp_ajax_ajax_data_smiley’, ‘Bing_ajax_data_smiley’ );

以上代码来源于:EndSkin

本文地址:https://boke112.com/post/668.html

赞 (0) 打赏
版权声明:本文为原创文章,版权归 boke112百科 所有,欢迎分享本文,转载请保留出处!发布此文是出于传递更多信息之目的,若有来源标注错误或侵犯了您的合法权益,请联系我们,确认后马上更正或删除,谢谢!
香港云主机55元/年
wu