我正在尝试在我的前端添加一个TinyMCE编辑器,用户可以在那里发帖,但到目前为止运气不佳。代码如下:
PHP:
add_action(\'wp_print_scripts\', \'my_enqueue_scripts\');
function my_enqueue_scripts() {
wp_enqueue_script( \'tiny_mce\' );
if (function_exists(\'wp_tiny_mce\')) wp_tiny_mce();
}
Javascript:
jQuery(document).ready(function(){
tinyMCE.init({
mode : "textareas",
theme : "simple",
/*plugins : "autolink, lists, spellchecker, style, layer, table, advhr, advimage, advlink, emotions, iespell, inlinepopups, insertdatetime, preview, media, searchreplace, print, contextmenu, paste, directionality, fullscreen, noneditable, visualchars, nonbreaking, xhtmlxtras, template",*/
editor_selector :"editor"
});
});
HTML:
<textarea rows="8" cols="40" name="description" id="editor" class="required"><?php echo $description;?></textarea>
Problem: Texteditor未添加到textarea。尽管TinyMCE js文件正在加载。
SO网友:maryisdead
editor_selector
用于定位类,而不是ID。
此外,使用时editor_selector
, 需要设置mode: "specific_textareas"
为了让它工作。
看见http://tinymce.moxiecode.com/wiki.php/Configuration:editor_selector
因此,您的JavaScript和HTML应该如下所示:
jQuery(document).ready(function(){
tinyMCE.init({
mode : "specific_textareas",
theme : "simple",
/*plugins : "autolink, lists, spellchecker, style, layer, table, advhr, advimage, advlink, emotions, iespell, inlinepopups, insertdatetime, preview, media, searchreplace, print, contextmenu, paste, directionality, fullscreen, noneditable, visualchars, nonbreaking, xhtmlxtras, template",*/
editor_selector :"tinymce-enabled"
});
});
<textarea rows="8" cols="40" name="description" id="editor" class="tinymce-enabled required"><?php echo $description;?></textarea>