我有一个wordpress主题,允许用户注册和创建帖子(qaengine是名称)。
我的用户要求我将markdown添加到文本编辑器中,所以我找到了一个很好的插件,它可以更改文本编辑器并允许插入markdown (wp-markdown)。问题是,wp-admin中的文本编辑器已经改变了,但我的用户界面上的文本编辑器没有受到影响,即使它们都是用于创建帖子/页面等的界面,并且基于插件的描述,它似乎应该适用。
每当我在谷歌上寻求帮助时,它只是关于文本编辑器的样式,所以我不知所措。
发布于 2019-01-30 04:55:28
要在qaengine主题的前端更改文本编辑器(TinyMCE),您需要使用子主题,创建一个文件function.php并将其复制到子主题文件夹中,然后插入以下函数:
function editor_settings($args = array()){
$buttons = apply_filters( 'qa_editor_buttons', 'formatselect | bold italic | redo undo | removeformat | link | alignright alignjustify alignleft aligncenter | numlist bullist outdent indent | qaimage | blockquote qacode' );
return array(
'quicktags' => false,
'media_buttons' => false,
'tabindex' => 5,
'textarea_name' => 'post_content',
'tinymce' => array(
'language' =>'en',
'height' => 150,
'toc_depth' => '3',
'toc_header' => "div",
'plugins' => "image imagetools table wordcount searchreplace preview autolink link advlist lists directionality paste toc",
'block_formats' => 'Paragraph=p;Heading 2=h2;Heading 3=h3;Heading 4=h4;Pre=pre;Code=code',
'toolbar' => '[
"redo undo formatselect bold italic removeformat alignment numlist bullist outdent indent qaimage link unlink",
"rtl ltr table searchreplace preview blockquote qacode toc copy"
]',
'autoresize_min_height' => 150,
'autoresize_max_height' => 400,
'force_p_newlines' => false,
'statusbar' => true,
'directionality' => 'ltr',
'paste_data_images' => true,
'setup' => "function(ed){
ed.onChange.add(function(ed, l) {
var content = ed.getContent();
if(ed.isDirty() || content === '' ){
ed.save();
jQuery(ed.getElement()).blur(); // trigger change event for textarea
}
});
// We set a tabindex value to the iframe instead of the initial textarea
ed.onInit.add(function() {
var editorId = ed.editorId,
textarea = jQuery('#'+editorId);
jQuery('#'+editorId+'_ifr').attr('tabindex', textarea.attr('tabindex'));
textarea.attr('tabindex', null);
});
ed.addButton('alignment', {
type: 'listbox',
text: 'Alignment',
icon: false,
onselect: function(e) {
tinyMCE.execCommand(this.value());
},
values: [
{icon: 'alignleft', text: 'Align left', value: 'JustifyLeft'},
{icon: 'alignright', text: 'Align right', value: 'JustifyRight'},
{icon: 'aligncenter', text: 'Align center', value: 'JustifyCenter'},
//{icon: 'alignjustify', text: 'Justify', value: 'JustifyFull'},
],
onPostRender: function() {
// Select the firts item by default
this.value('JustifyLeft');
}
});
}"
));
}ps:为了能够添加一些所需的按钮,必须在TinyMCE文件夹中安装一些TinyMCE插件。
https://stackoverflow.com/questions/49140048
复制相似问题