如何给WordPress主题评论框加上阿鲁表情
4286
本文是将大发贱志的阿鲁表情插件集成在你的主题上面,当然你也可以直接用插件!
GitHub地址:https://github.com/hayasuki/wp-alu
第一步
把下面代码添加到主题 functions.php文件中
function alu_scripts() { wp_enqueue_style( 'admin-myjscss', get_template_directory_uri() . '/static/css/style.css' ); wp_enqueue_script( 'admin-myjscss', get_template_directory_uri() . '/static/js/index.js' ); } add_action('admin_head', 'alu_scripts'); add_filter('smilies_src', 'alu_smilies_src', 1, 10); function alu_smilies_src($img_src, $img, $siteurl) { $img = rtrim($img, "gif"); return get_bloginfo('template_directory') . '/static/img/' . $img . 'gif'; } function alu_get_wpsmiliestrans() { global $wpsmiliestrans; $wpsmilies = array_unique($wpsmiliestrans); $output = ''; foreach ($wpsmilies as $alt => $src_path) { //$emoji = str_replace(array('&#x', ';'), '', wp_encode_emoji($src_path)); $output .= '<a class="add-smily" data-action="addSmily" data-smilies="' . $alt . '"><img class="wp-smiley" src="' . get_bloginfo('template_directory') . '/static/img/' . $src_path .'" /></a>'; } return $output; } function alu_smilies_reset() { global $wpsmiliestrans, $wp_smiliessearch; // don't bother setting up smilies if they are disabled if ( !get_option( 'use_smilies' ) ) return; $wpsmiliestrans = array( ':mrgreen:' => 'icon_mrgreen.gif', ':neutral:' => 'icon_neutral.gif', ':twisted:' => 'icon_twisted.gif', ':arrow:' => 'icon_arrow.gif', ':shock:' => 'icon_eek.gif', ':smile:' => 'icon_smile.gif', ':???:' => 'icon_confused.gif', ':cool:' => 'icon_cool.gif', ':evil:' => 'icon_evil.gif', ':grin:' => 'icon_biggrin.gif', ':idea:' => 'icon_idea.gif', ':oops:' => 'icon_redface.gif', ':razz:' => 'icon_razz.gif', ':roll:' => 'icon_rolleyes.gif', ':wink:' => 'icon_wink.gif', ':cry:' => 'icon_cry.gif', ':eek:' => 'icon_surprised.gif', ':lol:' => 'icon_lol.gif', ':mad:' => 'icon_mad.gif', ':sad:' => 'icon_sad.gif', '8-)' => 'icon_cool.gif', '8-O' => 'icon_eek.gif', ':-(' => 'icon_sad.gif', ':-)' => 'icon_smile.gif', ':-?' => 'icon_confused.gif', ':-D' => 'icon_biggrin.gif', ':-P' => 'icon_razz.gif', ':-o' => 'icon_surprised.gif', ':-x' => 'icon_mad.gif', ':-|' => 'icon_neutral.gif', ';-)' => 'icon_wink.gif', // This one transformation breaks regular text with frequency. // '8)' => 'icon_cool.gif', '8O' => 'icon_eek.gif', ':(' => 'icon_sad.gif', ':)' => 'icon_smile.gif', ':?' => 'icon_confused.gif', ':D' => 'icon_biggrin.gif', ':P' => 'icon_razz.gif', ':o' => 'icon_surprised.gif', ':x' => 'icon_mad.gif', ':|' => 'icon_neutral.gif', ';)' => 'icon_wink.gif', ':!:' => 'icon_exclaim.gif', ':?:' => 'icon_question.gif', ); } add_action('init','alu_smilies_reset'); add_filter( 'comment_form_defaults','alu_add_smilies_to_comment_form'); function alu_add_smilies_to_comment_form($default) { $commenter = wp_get_current_commenter(); $default['comment_field'] .= '<p class="comment-form-smilies">' . alu_get_wpsmiliestrans() . '</p>'; return $default; }
注意上面表情图片引用路径,根据自己实际情况修改
第二步
把下载下来的文件里面的static文件夹直接拖到你的主题文件里面
第三步
打开你主题文件里面的comments.php文件 搜索textarea 然后把下面代码放在textarea 之前就行了
<p class="comment-form-smilies"><?php echo alu_get_wpsmiliestrans();?></p>
本文网址:https://www.zztuku.com/index.php/detail-8958.html
站长图库 - 如何给WordPress主题评论框加上阿鲁表情
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!