Depending on the level of customization or the level of formatting your customer wants or you want to give your users as it relates to the WordPress post editor, you may need to remove TinyMCE buttons from the WordPress editor.
Although it’s relatively easy to remove all of the buttons and, say, focus only on the HTML view, it’s also possible to remove individual buttons from the post editor so that the user only has a subset of the options that are typically available.
Say, for example, you want to remove everything from the second row exception the formatting drop-down that let’s you select the heading size, paragraph, or
pre elements. It’s easy to do this using one of the hooks that WordPress provides.
Remove TinyMCE Buttons
Before looking at code for how to actually remove the buttons from the editor, it’s important to note that there are two hooks that are available in WordPress:
The hooks go all the way number to the number four, but as the Codex states:
By default, WordPress does not use/display this toolbar
This means that the only two filters with which we’re concerned are
me_buttons_2 and the rows of controls to which each of these correspond is pretty easy to remember:
- The first row of buttons refers to the top row of the editor (that is, the basic controls)
- The second row of buttons are those that are part of the ‘kitchen sink’ or the advanced controls
In this example, we’re looking to remove all of buttons except the element that allows us to select the type of formatting for our text. To do this, we need to setup a function that’s hooked to
Next, we need to remove all of the buttons from the array that we do not want to display. To do this, you need to know the key and value of the buttons that exist in the editor. There are a few ways to get them: You can iterate through the array in PHP and print the results out to the console, the error log, or to the the display.
Whatever you choose to do, you’ll come up with a list similar to what I have below. Note that I’ve specified everything except the button for the formatting:
Though this code is specifically for removing all but the post formatting button, here’s how it works:
- There’s an array that contains the IDs to all of the second row of post editor buttons
- When the function fires, it iterates through the list of buttons we want removed
- If the current iterations information is in the list of `$invalid_buttons`, it’s removed from the `$buttons` array.
- All other buttons remain and are returned to the caller which is obviously WordPress.
Clearly, this is but one example of how you can remove TinyMCE buttons from WordPress. If you’re looking to remove a single button, there’s no need for a loop or anything like that – you can just remove the identifier from the
But if you’re looking to do more than that, then the above solution should work just fine.
Leave a Reply
You must be logged in to post a comment.