Filters the list of TinyMCE external plugins.
Description
The filter takes an associative array of external plugins for TinyMCE in the form ‘plugin_name’ => ‘url’.
The url should be absolute, and should include the js filename to be loaded. For example: ‘myplugin’ => ‘http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js‘.
If the external plugin adds a button, it should be added with one of the ‘mce_buttons’ filters.
Parameters
$external_plugins
array- An array of external TinyMCE plugins.
$editor_id
string- Unique editor identifier, e.g.
'content'
. Accepts'classic-block'
when called from block editor’s Classic block.
Source
$mce_external_plugins = apply_filters( 'mce_external_plugins', array(), $editor_id );
Example migrated from Codex:
Visualblock plugin
For example, you might create a WordPress plugin that loads the TinyMCE plugin visualblocks.
TinyMCE plugins typically consist of a javascript file named ‘editor_plugin.js’ and a series of CSS files and other helper files. This example assumes the WordPress plugin stores TinyMCE plugins as follows: example_plugin/tinymce/visualblocks/edior_plugin.js
Example migrated from Codex:
Creating a shortcode and a tag button
First, create a plugin that registers the buttons and their JavaScript.
Then, in the same folder as the plugin, the JavaScript file mybuttons.js. We add our two buttons (eek and green), one is a direct
onclick
that inserts a Shortcode and the other is a command that adds anh3
tag to the selected text in the editor.You can pass PHP values to the JavaScript file printing directly in
admin_head
:And then, access it in mybuttons.js with
console.log(my_plugin.url);
.