梦站博客-免费资源
  技术教程分享平台

非插件给WordPress编辑器添加表情按钮

主题函数代码

首先给自己的主题的functions.php添加如下代码:

  1. //输出WordPress表情function fa_get_wpsmiliestrans(){        global $wpsmiliestrans;        $wpsmilies = array_unique($wpsmiliestrans);        foreach($wpsmilies as $alt => $src_path){            $output .= ‘<a class=”add-smily” data-smilies=”‘.$alt.'”></a>’;        }        return $output;}     add_action(‘media_buttons_context’, ‘fa_smilies_custom_button’);function fa_smilies_custom_button($context) {        $context .= ‘<style>.smilies-wrap{background:#fff;border: 1px solid #ccc;box-shadow: 2px 2px 3px rgba(0, 0, 0, 0.24);padding: 10px;position: absolute;top: 60px;width: 380px;display:none}.smilies-wrap img{height:24px;width:24px;cursor:pointer;margin-bottom:5px} .is-active.smilies-wrap{display:block}</style><a id=”insert-media-button” style=”position:relative” class=”button insert-smilies add_smilies” title=”添加表情” data-editor=”content” href=”javascript:;”>    添加表情</a><div class=”smilies-wrap”>’. fa_get_wpsmiliestrans() .'</div><script>jQuery(document).ready(function(){jQuery(document).on(“click”, “.insert-smilies”,function() { if(jQuery(“.smilies-wrap”).hasClass(“is-active”)){jQuery(“.smilies-wrap”).removeClass(“is-active”);}else{jQuery(“.smilies-wrap”).addClass(“is-active”);}});jQuery(document).on(“click”, “.add-smily”,function() { send_to_editor(” ” + jQuery(this).data(“smilies”) + ” “);jQuery(“.smilies-wrap”).removeClass(“is-active”);return false;});});</script>’;        return $context;}

自定义表情图片

将以下代码加入functions.php文件中

  1. add_filter(‘smilies_src’,’fa_smilies_src’,1,10);function fa_smilies_src ($img_src, $img, $siteurl){$img = rtrim($img, “gif”);return get_bloginfo(‘template_directory’).’/img/smilies/’.$img.’png’;}

    嘉华在线

    雅星娱乐

    恩佐娱乐

未经允许不得转载:emlog梦站 » 非插件给WordPress编辑器添加表情按钮