首页 文章

Wordpress - 在另一个文本编辑器中添加自定义的tinymce短代码,而不仅仅是经典编辑器

提问于
浏览
1

在这里我的问题:我有一些不同的文本区域(不是Wordpress Classic Editor,而是Visual Composer插件中的许多Wysiwyg编辑器) . 我的主题包括一些短代码 . 但是当我想在特定的textarea中插入短代码时,短代码每次都出现在经典编辑器中 . 所以我会试着在代码中说“将代码放在我要插入短代码的文本框中,而不是传统的发布者” . 在这里我的代码我认为解决方案可能是:

addWithPopup: function(ed, title, id) {
        ed.add({
            title: title,
            onclick: function() {
                tinyMCE.activeEditor.execCommand('FreshShortcodesPopup', false, {
                    title: title,
                    identifier: id
                });
            }
        });
    },

希望你能帮帮我...问候 . 数学 .

1 回答

  • 0

    不要使用 tinyMCE.activeEditor 来寻址编辑器 . 除非用户明确单击另一个编辑器,否则 tinyMCE.activeEditor 不会更改 . 另一个陷阱是 tinyMCE.activeEditor 未初始化,除非单击一个编辑器 . 最好使用其id来解决编辑器实例:

    tinymce.get('your_editor_id').execCommand(...
    

    更新:怎么样

    onclick: function(ed) {
               console.log('ed:',ed);
               ed.execCommand('FreshShortcodesPopup', false, {
                    title: title,
                    identifier: id
                });
            }
    

相关问题