通过将TinyMCE添加到我的子主题函数中,我在post comment textarea中添加了TinyMCE。php
function rich_text_comment_form( $args ) {
ob_start();
wp_editor( \'\', \'comment\', array(
\'media_buttons\' => true, // show insert/upload button(s) to users with permission
\'textarea_rows\' => \'10\', // re-size text area
\'dfw\' => false, // replace the default full screen with DFW (WordPress 3.4+)
\'tinymce\' => array(
\'theme_advanced_buttons1\' => \'bold,italic,underline,strikethrough,bullist,numlist,code,blockquote,link,unlink,outdent,indent,undo,redo,fullscreen\',
\'theme_advanced_buttons2\' => \'\', // 2nd row, if needed
\'theme_advanced_buttons3\' => \'\', // 3rd row, if needed
\'theme_advanced_buttons4\' => \'\' // 4th row, if needed
)
));
$args[\'comment_field\'] = ob_get_clean();
return $args;
}
add_filter( \'comment_form_defaults\', \'rich_text_comment_form\' );
结果如下:
我尝试用字体图标替换工具栏按钮内的文本。问题是不可能向输入元素添加伪元素。因此,我决定用以下内容将其包装到标签标签中:
$(\'#qt_comment_toolbar input\').each(function() {
var id = $(\'#qt_comment_toolbar input\').attr(\'id\');
$(\'#qt_comment_toolbar input\').wrap(\'<label class"label-\' + id + \'" for="\' + id + \'"></label>\');
});
但这不起作用,我不明白为什么。我需要将输入嵌套到标签中,然后才能向该标签添加伪元素。以下是HTML部分:
<div id="qt_comment_toolbar" class="quicktags-toolbar">
<input type="button" id="qt_comment_strong" class="ed_button button button-small" aria-label="Bold" value="b">
<input type="button" id="qt_comment_em" class="ed_button button button-small" aria-label="Italic" value="i">
<input type="button" id="qt_comment_link" class="ed_button button button-small" aria-label="Insert link" value="link">
<input type="button" id="qt_comment_block" class="ed_button button button-small" aria-label="Blockquote" value="b-quote">
<input type="button" id="qt_comment_del" class="ed_button button button-small" aria-label="Deleted text (strikethrough)" value="del"><input type="button" id="qt_comment_ins" class="ed_button button button-small" aria-label="Inserted text" value="ins">
<input type="button" id="qt_comment_img" class="ed_button button button-small" aria-label="Insert image" value="img">
<input type="button" id="qt_comment_ul" class="ed_button button button-small" aria-label="Bulleted list" value="ul">
<input type="button" id="qt_comment_ol" class="ed_button button button-small" aria-label="Numbered list" value="ol">
<input type="button" id="qt_comment_li" class="ed_button button button-small" aria-label="List item" value="li">
<input type="button" id="qt_comment_code" class="ed_button button button-small" aria-label="Code" value="code">
<input type="button" id="qt_comment_more" class="ed_button button button-small" aria-label="Insert Read More tag" value="more">
<input type="button" id="qt_comment_close" class="ed_button button button-small" title="Close all open tags" value="close tags">
</div>
此外,我不明白为什么TinyMCE显示文本按钮而不是图标,正如我在页面/帖子编辑器中看到的那样(在视觉模式下禁用Gutenberg)。这是一个问题TinyMCE主题还是版本?
希望我足够清楚。感谢您阅读本文。