This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
mce_external_languages filter
The filter takes an associative array (‘plugin_name’ => ‘path’) where ‘path’ is the include path to the file.
To use mce_external_languages filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.
We at WePlugins always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function modify_mce_external_languages_defaults which takes 2 parameters and we registered using add_filter. The first parameter mce_external_languages is name of the hook, The second parameter modify_mce_external_languages_defaults is name of the function which need to be called, third parameter is the priority of calling the hook if same hook is used multiple times and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometime, you have to remove a registered hook so you can use remove_filter to remove mce_external_languages filter.
Parameters
Below are the 2 parameters required to use this hook.
- $translations: (array) Translations for external TinyMCE plugins.
- $editor_id: (string) Unique editor identifier, e.g. ‘content’.
Live Examples
Example 1: Adding a Custom TinyMCE Plugin Locale
Here is how you can add a custom TinyMCE plugin locale using this hook.
add_filter('mce_external_languages', 'weplugins_custom_tinymce_plugin_add_locale'); function weplugins_custom_tinymce_plugin_add_locale($locales) { $locales['My-Custom-Tinymce-Plugin'] = plugin_dir_path(__FILE__) . 'my-custom-tinymce-plugin-langs.php'; return $locales; }
Example 2: Modifying Default Translations
Modify the $translations variable according to your website requirements.
function weplugins_modify_mce_external_languages_defaults($translations, $editor_id) { // Update the $translations variable conditionally if needed. return $translations; } // add the filter add_filter('mce_external_languages', 'weplugins_modify_mce_external_languages_defaults', 10, 2);
Example 3: Removing a Hook Callback
To remove a hook callback, use the example below. Make sure to provide the same callback function name, priority, and number of arguments.
remove_filter('mce_external_languages', 'weplugins_modify_mce_external_languages_defaults', 10, 2);
Contact Us
If you need customization or are having any trouble using this hook, please contact us and we’d be happy to assist you.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.