简体   繁体   English

当我调用tinymce.init时,WordPresspress tinymce编辑器会发生变化

[英]Wordpress tinymce editor changes when I call tinymce.init

I am trying to set the content of a tinymce editor in a plugin and I can change the content but the appearance of the editor changes when I use this code 我正在尝试在插件中设置tinymce编辑器的内容,我可以更改内容,但是当我使用此代码时编辑器的外观会发生变化

jQuery(document).ready(function($) {
var name1 = "wprsspostprepend";
if($("#" + name1).length > 0) {

  tinyMCE.init({
    selector : "#wprsspostprepend",
     setup: function (editor) {
    editor.on('init', function () {
      var selector = tinyMCE.get('wprsspostprepend');
      var content =  selector.getContent();
   selector.setContent("<div id='random-wrap'>" + content + "</div>");
    });
  }
});

}


 });

I lose all the Wordpress plugin icons from the menu bar and it changes to just a stock editor. 我从菜单栏中丢失了所有Wordpress插件图标,并且它变成了一个股票编辑器。

How can I set the content of the editor without changing the appearance? 如何在不更改外观的情况下设置编辑器的内容?

I'd imagine that this is due to you prepending everything to the content including the content itself. 我想这是由于您将所有内容放在内容之前,包括内容本身。

Try something like this; 尝试这样的事情;

jQuery(document).ready(function($) {
    var name1 = "wprsspostprepend";
    if($("#" + name1).length > 0) {
        tinyMCE.init({
            selector : "#wprsspostprepend",
            setup: function (editor) {
                editor.on('init', function () {
                    var pre = tinyMCE.get('wprsspostprepend');
                    var content = pre.getContent();
                    selector.setContent("<div id='random-wrap'>");
                });
            }
        });
     }
});

Then just add a closing div tag via the append attribute 然后只需通过append属性添加一个结束div标签

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM