我试着把<textarea>
使用表情符号选择器(https://github.com/mervick/emojionearea) 在我的wordpress站点中(安装了buddypress,实际上我把它放在buddypress消息中)。基本代码非常简单。
Exemple: https://jsfiddle.net/fqo1za9u/
一瞥:
HTML head:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/mervick/emojionearea/master/dist/emojionearea.js"></script>
<link rel="stylesheet" href="https://rawgit.com/mervick/emojionearea/master/dist/emojionearea.css">
HTML body:
<textarea class="emojitextarea"></textarea>
<script type="text/javascript">
$(document).ready(function() {
$(".emojitextarea").emojioneArea({
pickerPosition: "bottom"
});
});
</script>
在我的
function.php
(我已经检查了文件夹路径,没问题):
function my_add_scripts_style_emoji()
{
wp_register_script(\'my-script-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.js\', array(\'jquery\'), \'1.0\', false);
wp_enqueue_script(\'my-script-emojionearea\');
wp_enqueue_style(\'my-styles-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.css\', array(), \'1.0\');
}
add_action(\'wp_enqueue_scripts\', \'my_add_scripts_style_emoji\');
在我的文本区域文件中:
<textarea class="emojitextarea"></textarea>
<script type="text/javascript">
jQuery(document).ready(function() {
$(".emojitextarea").emojioneArea({
pickerPosition: "bottom"
});
});
</script>
一
function my_add_scripts_style_emoji()
{
wp_register_script(\'my-script-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.js\', array(\'jquery\'), \'1.0\', false);
wp_enqueue_script(\'my-script-emojionearea\');
wp_enqueue_style(\'my-styles-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.css\', array(), \'1.0\');
}
add_action(\'wp_enqueue_scripts\', \'my_add_scripts_style_emoji\');
function my_add_scripts_style_emoji()
{
wp_register_script(\'my-script-jquery\', \'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js\', array(\'jquery\'), \'1.0\', false);
wp_enqueue_script(\'my-script-jquery\');
wp_register_script(\'my-script-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.js\', array(\'jquery\'), \'1.0\', false);
wp_enqueue_script(\'my-script-emojionearea\');
wp_enqueue_style(\'my-styles-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.css\', array(), \'1.0\');
}
add_action(\'wp_enqueue_scripts\', \'my_add_scripts_style_emoji\');
所以,如果我能很好地理解,
the problem is that a core jquery version file is not loaded correctly. But I thought, core jquery file is loaded by default in my WP header?I also tried this (manuel enqueue core jquery file), with no succes:
function my_add_scripts_style_emoji()
{
wp_enqueue_script(\'jquery\');
wp_register_script(\'my-script-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.js\', array(\'jquery\'), \'1.0\', false);
wp_enqueue_script(\'my-script-emojionearea\');
wp_enqueue_style(\'my-styles-emojionearea\', get_stylesheet_directory_uri() . \'/emoji/emojionearea.css\', array(), \'1.0\');
}
add_action(\'wp_enqueue_scripts\', \'my_add_scripts_style_emoji\');
如果我理解得很好,那么最好使用WP核心jquery版本,而不是使用自己的jquery版本。所以,为什么这在这里不起作用,而使它起作用的唯一方法是加载您自己版本的jquery?有什么想法吗?