Using WordPress ‘mce_external_plugins’ PHP filter

The mce_external_plugins WordPress PHP filter allows you to add external TinyMCE plugins to the WordPress editor.

Usage

add_filter('mce_external_plugins', 'my_custom_external_plugins');
function my_custom_external_plugins($plugins) {
    // your custom code here
    return $plugins;
}

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.

More information

See WordPress Developer Resources: mce_external_plugins

Examples

Add an external plugin to TinyMCE

This example adds a custom external plugin called ‘myplugin’ to the WordPress editor:

add_filter('mce_external_plugins', 'my_custom_external_plugins');
function my_custom_external_plugins($plugins) {
    $plugins['myplugin'] = 'https://example.com/wp-content/plugins/myplugin/mce_plugin.js';
    return $plugins;
}

Add multiple external plugins

This example shows how to add multiple external plugins to the WordPress editor:

add_filter('mce_external_plugins', 'my_custom_external_plugins');
function my_custom_external_plugins($plugins) {
    $plugins['plugin_one'] = 'https://example.com/wp-content/plugins/plugin_one/mce_plugin.js';
    $plugins['plugin_two'] = 'https://example.com/wp-content/plugins/plugin_two/mce_plugin.js';
    return $plugins;
}

Remove an external plugin

This example demonstrates how to remove an external plugin from the WordPress editor:

add_filter('mce_external_plugins', 'my_custom_remove_external_plugins');
function my_custom_remove_external_plugins($plugins) {
    unset($plugins['plugin_to_remove']);
    return $plugins;
}

Add external plugin only for specific editor ID

This example adds an external plugin to the WordPress editor only for a specific editor ID:

add_filter('mce_external_plugins', 'my_custom_external_plugins', 10, 2);
function my_custom_external_plugins($plugins, $editor_id) {
    if ($editor_id === 'my_editor_id') {
        $plugins['myplugin'] = 'https://example.com/wp-content/plugins/myplugin/mce_plugin.js';
    }
    return $plugins;
}

Add external plugin with a specific button

This example adds an external plugin to the WordPress editor along with a button to access the plugin’s functionality:

add_filter('mce_external_plugins', 'my_custom_external_plugins');
function my_custom_external_plugins($plugins) {
    $plugins['myplugin'] = 'https://example.com/wp-content/plugins/myplugin/mce_plugin.js';
    return $plugins;
}

add_filter('mce_buttons', 'my_custom_mce_buttons');
function my_custom_mce_buttons($buttons) {
    array_push($buttons, 'myplugin_button');
    return $buttons;
}