Home >php教程 >php手册 >在主题模板函数直接添加额外表情的function

在主题模板函数直接添加额外表情的function

WBOY
WBOYOriginal
2016-06-06 20:08:301093browse

把Wordpress默认表情修改为自定义表情大家都很熟悉,增加额外的表情也应该听说过(可在本站搜索"wordpress添加自定义表情不被识别的解决方法"),我看了一下,网上关于增加额外表情的方法除了安装customs smilies插件,就只剩下去wp-includes修改functions了,这个

把Wordpress默认表情修改为自定义表情大家都很熟悉,增加额外的表情也应该听说过(可在本站搜索"wordpress添加自定义表情不被识别的解决方法"),我看了一下,网上关于增加额外表情的方法除了安装customs smilies插件,就只剩下去wp-includes修改functions了,这个方法当然不好,因为wordpress一更新,就又得重新去改函数,接下来我就为大家介绍如果在主题的functions.php里添加函数来添加表情,这样做的好处就和修改表情图片文件夹一样,不赘述了.
老样子首先我们来看原理(不看原理这文章实在写不长),在wp-includes→functions.php里,搜索smiley找到smilies_init这个函数,

function smilies_init() {
global $wpsmiliestrans, $wp_smiliessearch;
// don't bother setting up smilies if they are disabled
if ( !get_option( 'use_smilies' ) )
return;
if ( !isset( $wpsmiliestrans ) ) {
$wpsmiliestrans = array(
':mrgreen:' => 'icon_mrgreen.gif',
':neutral:' => 'icon_neutral.gif',
//....此处省略一千字...

由此可知,$wpsmiliestrans这个数组定义了表情的输出,
所以接下来我们要做的就是直接在主题的functions.php内加入如下代码,以重新定义数组

global $wpsmiliestrans;
$wpsmiliestrans = array(
':new:' => 'new.gif',
':new1:' => 'new1.gif',
':new2:' => 'new2.gif',
':new3:' => 'new3.gif',
':new4:' => 'new4.gif',
//以此类推...
);

好了,就这么多,以后不怕wordpress更新了.老公今天来天津了,晚上就不陪你们大白话了,嘻嘻.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn