簡體   English   中英

如何在tinymce編輯器中刪除非默認wordpress編輯器的按鈕

[英]How to remove buttons in tinymce editor for the non-default wordpress editor

我可以看到許多有關在tinymce編輯器中刪除按鈕的示例,但是我想對我從Javascript添加的自定義編輯器執行此操作。

function myplugin_tinymce_buttons( $buttons ) {
  //Remove the text color selector
  $remove = 'forecolor';

  //Find the array key and then unset
  if ( ( $key = array_search( $remove, $buttons ) ) !== false )
    unset( $buttons[$key] );

  return $buttons;
}

這里沒有提及編輯器ID。 我該如何僅對自定義編輯器執行此操作? 我不想更改Wordpress帖子頁面中顯示的主編輯器中的任何內容。

最好和最干凈的方法肯定是初始化之前更改TinyMCE配置。

否則,您可以參考另一個問題的答案 ,即我將編輯器設置為只讀模式,然后僅啟用幾個按鈕。

我沒有測試此代碼,但您的函數應如下所示:

function removeButton(editorId, pluginName, commandName) {
    var htmlEditorDiv = document.getElementById(editorId).previousSibling;
    var editor = tinymce.get(editorId);
    var buttonDiv = htmlEditorDiv.querySelectorAll('.mce-i-' + pluginName.toLowerCase())[0].parentElement.parentElement;
    buttonDiv.style.display = "none";
    buttonDiv.firstChild.onclick = function () {
        //Even if the button is invisible, it's better
        //removing the command associated to the button click just in case
    };
}

有關命令列表,請參閱此頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM