rysv
rysv

Reputation: 3440

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

I can see numerous examples on removing buttons in the tinymce editor but I want to do this for a custom editor I am adding from 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;
}

There is no mention of editor ID here. How do I do this only for a custom editor? I dont want to change anything in the main editor shown in Wordpress post page.

Upvotes: 0

Views: 1268

Answers (1)

Jérôme MEVEL
Jérôme MEVEL

Reputation: 7822

The best and cleanest way is definitely to change your TinyMCE config before initialization.

Otherwise you can refer to my answer on another question where I set the editor in ReadOnly mode then enable just few buttons.

I didn't test this code but your function should be something like this:

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
    };
}

For the list of commands, refer to this page

Upvotes: 1

Related Questions