我每天都喜欢登录到WordPress后台,如果有评论需要回复时就直接在后台回复,而不想打开文章页再回复,但是这有一个弊端,那就是在后台评论时,无法使用表情,感觉非常不好。所以今天就分享一下如何在WordPress后台回复评论处添加表情功能。
具体的操作步骤如下:
1、下载《如何替换WordPress的默认评论表情?》这篇文章中的smiley.php文件(PS:或自己所使用主题中的smiley.php)。
2、在smiley.php文件中找到下列代码:
- if (document.getElementById(‘comment’) && document.getElementById(‘comment’).type == ‘textarea’) {myField = document.getElementById(‘comment’);
替换为(或直接注释掉以上代码):
- 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文件,在
- <?php _e( ‘Reply to Comment’ ); ?>
后面(448行左右)添加如下代码,并保存覆盖。
- <?php include_once“smiley.php” ?>
至此,已经成功实现WordPress后台回复评论处添加表情功能了,不过美中不足的就是有两个缺点:
1、在后台首页进行回复评论还是无法使用表情,必须点击左侧的“评论”,在出现的评论中回复才能使用表情。
2、WordPress升级后,必须重新更新/wp-admin/includes/template.php文件。
不过这些缺点不影响操作,不介意的可以折腾折腾!
以上代码来源于:Gimhoy
第二种方法是直接集成到主题中,只需要把下边的代码添加到当前主题的 functions.php最后一个?>前面即可。
- /**
- *WordPress 后台回复评论插入表情
- *http://www.endskin.com/admin-smiley.html
- */
- function Bing_ajax_smiley_scripts(){
- 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>’;
- }
- add_action( ‘admin_head’, ‘Bing_ajax_smiley_scripts’ );
- //Ajax 获取表情
- function Bing_ajax_data_smiley(){
- $site_url = site_url();
- foreach( array_unique( (array) $GLOBALS[‘wpsmiliestrans’] ) as $key => $value ){
- $src_url = apply_filters( ‘smilies_src’, includes_url( ‘images/smilies/’ . $value ), $value, $site_url );
- echo ‘ <a href=“javascript:grin(\” . $key . ‘\’)”><img src=“‘ . $src_url . ‘” alt=“‘ . $key . ‘” /></a> ‘;
- }
- die;
- }
- add_action( ‘wp_ajax_nopriv_ajax_data_smiley’, ‘Bing_ajax_data_smiley’ );
- add_action( ‘wp_ajax_ajax_data_smiley’, ‘Bing_ajax_data_smiley’ );
以上代码来源于:EndSkin