山东时时彩怎么中奖|十一运夺金山东时时彩|
点击登录
  • 欢迎访问好资源,这里会在第一时间更新最新最好的资源给您,如果您有好的资源、文章,可投稿。如有其他需要请联系 QQ 点我注册
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏好资源吧~ 点我注册

给WordPress编辑器添加表情按钮,让文章萌萌哒!

本文最后更新于2014年11月21日,已超过 1 年没有更新,如果文章内容或?#35745;?#36164;源失效,请留言反馈,我们会及时处理,谢谢!

WordPress默认编辑器添加表情按钮,自由的给文章添?#29992;?#33804;的表情,让文章萌起来23333

给WordPress编辑器添加表情按钮,让文章萌萌哒!

前言

传说有一种人叫表情;-) ,不管发什么都想带几个表情 :oops: ,但是WordPress自带的编辑器确?#30340;?#26377;表情按钮,这让身为表情控的博猪情?#25105;?#22570;,经过博猪百度一下,谷歌两下,找到了比较不错的解决方案了 :cool:

函数代码

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

<span class="com"><span class="com">//输出<a href="http://www.eeeptk.tw/?tag=wordpress" title="查看更多关于WordPress的文章" target="_blank">WordPress</a><a href="http://www.eeeptk.tw/?tag=%e8%a1%a8%e6%83%85" title="查看更多关于表情的文章" target="_blank">表情</a></span></span>
<span class="kwd"><span class="kwd">function</span></span><span class="pln"><span class="pln"> fa_get_wpsmiliestrans</span></span><span class="pun"><span class="pun">(){</span></span>
<span class="kwd"><span class="kwd">global</span></span><span class="pln"><span class="pln"> $wpsmiliestrans</span></span><span class="pun"><span class="pun">;</span></span><span class="pln"><span class="pln">
$wpsmilies </span></span><span class="pun"><span class="pun">=</span></span><span class="pln"><span class="pln"> array_unique</span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$wpsmiliestrans</span></span><span class="pun"><span class="pun">);</span></span>
<span class="kwd"><span class="kwd">foreach</span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$wpsmilies </span></span><span class="kwd"><span class="kwd">as</span></span><span class="pln"><span class="pln"> $alt </span></span><span class="pun"><span class="pun">=></span></span><span class="pln"><span class="pln"> $src_path</span></span><span class="pun"><span class="pun">){</span></span><span class="pln"><span class="pln">
$output </span></span><span class="pun"><span class="pun">.=</span></span> <span class="str"><span class="str">'<a class="add-smily" data-smilies="'</span></span><span class="pun"><span class="pun">.</span></span><span class="pln"><span class="pln">$alt</span></span><span class="pun"><span class="pun">.</span></span><span class="str"><span class="str">'"><img class="wp-smiley" src="'</span></span><span class="pun"><span class="pun">.</span></span><span class="pln"><span class="pln">get_bloginfo</span></span><span class="pun"><span class="pun">(</span></span><span class="str"><span class="str">'template_directory'</span></span><span class="pun"><span class="pun">).</span></span><span class="str"><span class="str">'/img/smilies/'</span></span><span class="pun"><span class="pun">.</span></span><span class="pln"><span class="pln">rtrim</span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$src_path</span></span><span class="pun"><span class="pun">,</span></span> <span class="str"><span class="str">"gif"</span></span><span class="pun"><span class="pun">).</span></span><span class="str"><span class="str">'gif" /></a>'</span></span><span class="pun"><span class="pun">;</span></span>
<span class="pun"><span class="pun">}</span></span>
<span class="kwd"><span class="kwd">return</span></span><span class="pln"><span class="pln"> $output</span></span><span class="pun"><span class="pun">;</span></span>
<span class="pun"><span class="pun">}</span></span><span class="pln"><span class="pln">
add_action</span></span><span class="pun"><span class="pun">(</span></span><span class="str"><span class="str">'media_buttons_context'</span></span><span class="pun"><span class="pun">,</span></span> <span class="str"><span class="str">'fa_smilies_custom_button'</span></span><span class="pun"><span class="pun">);</span></span>
<span class="kwd"><span class="kwd">function</span></span><span class="pln"><span class="pln"> fa_smilies_custom_button</span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$context</span></span><span class="pun"><span class="pun">)</span></span> <span class="pun"><span class="pun">{</span></span><span class="pln"><span class="pln">
$context </span></span><span class="pun"><span class="pun">.=</span></span> <span class="str"><span class="str">'<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="添加<a href="http://www.eeeptk.tw/?tag=%e8%a1%a8%e6%83%85" title="查看更多关于表情的文章" target="_blank">表情</a>" data-editor="content" href="javascript:;">
添加表情
</a><div class="smilies-wrap">'</span></span><span class="pun"><span class="pun">.</span></span><span class="pln"><span class="pln"> fa_get_wpsmiliestrans</span></span><span class="pun"><span class="pun">()</span></span> <span class="pun"><span class="pun">.</span></span><span class="str"><span class="str">'</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>'</span></span><span class="pun"><span class="pun">;</span></span>
<span class="kwd"><span class="kwd">return</span></span><span class="pln"><span class="pln"> $context</span></span><span class="pun"><span class="pun">;</span></span>
<span class="pun"><span class="pun">}</span></span>

自定义表情?#35745;?/h2>

将以下代码加入functions.php文件,可能很多主题已经做到了表情自定义了,这个可以忽略,具体看自己的主题吧 :mrgreen:

<span class="pln"><span class="pln">add_filter</span></span><span class="pun"><span class="pun">(</span></span><span class="str"><span class="str">'smilies_src'</span></span><span class="pun"><span class="pun">,</span></span><span class="str"><span class="str">'fa_smilies_src'</span></span><span class="pun"><span class="pun">,</span></span><span class="lit"><span class="lit">1</span></span><span class="pun"><span class="pun">,</span></span><span class="lit"><span class="lit">10</span></span><span class="pun"><span class="pun">);</span></span>
<span class="kwd"><span class="kwd">function</span></span><span class="pln"><span class="pln"> fa_smilies_src </span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$img_src</span></span><span class="pun"><span class="pun">,</span></span><span class="pln"><span class="pln"> $img</span></span><span class="pun"><span class="pun">,</span></span><span class="pln"><span class="pln"> $siteurl</span></span><span class="pun"><span class="pun">){</span></span><span class="pln"><span class="pln">
$img </span></span><span class="pun"><span class="pun">=</span></span><span class="pln"><span class="pln"> rtrim</span></span><span class="pun"><span class="pun">(</span></span><span class="pln"><span class="pln">$img</span></span><span class="pun"><span class="pun">,</span></span> <span class="str"><span class="str">"gif"</span></span><span class="pun"><span class="pun">);</span></span>
<span class="kwd"><span class="kwd">return</span></span><span class="pln"><span class="pln"> get_bloginfo</span></span><span class="pun"><span class="pun">(</span></span><span class="str"><span class="str">'template_directory'</span></span><span class="pun"><span class="pun">).</span></span><span class="str"><span class="str">'/img/smilies/'</span></span><span class="pun"><span class="pun">.</span></span><span class="pln"><span class="pln">$img</span></span><span class="pun"><span class="pun">.</span></span><span class="str"><span class="str">'png'</span></span><span class="pun"><span class="pun">;</span></span>
<span class="pun"><span class="pun">}</span></span>

效果图

给WordPress编辑器添加表情按钮,让文章萌萌哒!

后语

一篇文章如果?#30475;?#37117;是文字的话看乏力,图文并茂才是王道,?#27604;?#25991;章多几个萌萌的表情,会让文章变得生动不小,这篇文章的代码就可以在编辑器直接插入表情按钮,省的还需要自己插入表情代码。

相关链接

?#21483;蜵Q表情下载

相关代码来自于大发 :shock:?

好资源 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明给WordPress编辑器添加表情按钮,让文章萌萌哒!
?#19981;?(15)
[捐赠网站,支持好资源!]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(6)个小伙伴在吐槽
  1. 多发精品,支持
    懒人天下2014-11-21 14:29 回复 Windows XP | Firefox浏览器 33.0
  2. 想试试
    Pang2015-03-16 16:50 回复 Windows 8 | Chrome 41.0.2272.89
  3. 表情下载不了,能发一份给我吗,谢谢 [email protected]
    蜂哥2015-03-26 16:32 回复 Windows XP | Chrome 33.0.1750.117
  4. 你?#33579;?#25353;您的教程修改后发?#31181;?#26174;示了部分表情的,想请教下什么原因啊。。。 :arrow:
    IzY2015-06-05 15:33 回复 Windows 7 | Firefox浏览器 38.0
  5. :mrgreen: 试试
    小义2015-08-20 15:18 回复 Windows 10 | Chrome 42.0.2311.152
  6. 试试 :mrgreen: :razz:
    aa2015-09-16 14:16 回复 Windows 8 | Firefox浏览器 40.0
山东时时彩怎么中奖