首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何更改主题的默认编辑器?

如何更改主题的默认编辑器?
EN

Stack Overflow用户
提问于 2018-03-07 05:13:13
回答 1查看 65关注 0票数 0

我有一个wordpress主题,允许用户注册和创建帖子(qaengine是名称)。

我的用户要求我将markdown添加到文本编辑器中,所以我找到了一个很好的插件,它可以更改文本编辑器并允许插入markdown (wp-markdown)。问题是,wp-admin中的文本编辑器已经改变了,但我的用户界面上的文本编辑器没有受到影响,即使它们都是用于创建帖子/页面等的界面,并且基于插件的描述,它似乎应该适用。

每当我在谷歌上寻求帮助时,它只是关于文本编辑器的样式,所以我不知所措。

EN

回答 1

Stack Overflow用户

发布于 2019-01-30 04:55:28

要在qaengine主题的前端更改文本编辑器(TinyMCE),您需要使用子主题,创建一个文件function.php并将其复制到子主题文件夹中,然后插入以下函数:

代码语言:javascript
复制
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插件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49140048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档