How is it possible to add a custom button to the visual editor TinyMCE, Version 4?
Currently I found this q&a with a little bit hints to the topic, but not a solution or a how to. But I can’t find a tutorial, documentation, q&a for the topic to add a custom button to the TinyMCE version 4, include in WordPress since version 3.9-beta1.
Goal
The following small plugin creates a custom button inside line 1 of the WordPress TinyMCE Version 4, tested in WP Version 3.9-beta2.
The plugin has
var_dump
included to understand the values. It’s also possible to add the button to other lines of the visual editor, only a other hook, like for line 2:mce_buttons_2
.Result
Plugin, PHP side –
tinymce4-test.php
Script, JavaScript side –
plugin.js
Gist
Use the Gist bueltge/9758082 as reference, or download. The Gist also has more examples for different buttons in TinyMCE.
Links
And, if you’d like to have an actual icon button, then you can leverage dashicons, or your own icon font for it.
Create a CSS file, and enqueue on the admin side;
Basically taken straight from core.
The simple method of adding button
1) ADD THIS CODE INTO FUNCTIONS.PHP, OR IN PLUGIN
2) Create 1_button.php in target folder and insert this code (note, change “wp-load” and “ButtonImage.png” urls!!!)