1

I had found a TinyMCE's plugin that change the direction of selected text. How to add this plugin in wordpress? Any one guide me?

I had tried to add it in /wp-includes/tinymce/plugin/custom-dir/plugin.js but what to do next to register it with wordpress. Its basic question but I am new to Wordpress. Thanks

3

You can register TinyMCE plugins using mce_external_plugins filter:

add_filter('mce_external_plugins', 'my_tinymce_plugins');
function my_tinymce_plugins() {
    $plugins_array = array(
                         'my-tinymce-plugin-name' => 'tinymce-plugin-url-of-js-file'
                     );
    return $plugins_array;
}

You can add that code to functions.php file of your theme, or better in a WordPress plugin to make it theme independent.

Also, I recommend to not upload externa tinymce plugins to wp-include /wp-includes/tinymce/ folder; use a WordPress plugin or theme folder instead.

For example, I've made this test. I've created a file called editor_plugin.js with the content of the TinyMCE plugin js file. I've uploaded it to my theme root folder and I've added this code to functions.php:

add_filter('mce_external_plugins', 'my_tinymce_plugins');
function my_tinymce_plugins() {
    $plugins_array = array(
                          'zbdo' => get_template_directory_uri().'/editor_plugin.js'
                     );
    return $plugins_array;
}
  • Much thanks for answer. Please guide me some more that what is 'my-tinymce-plugin-name' means? name of js plugin file? – John Doe Dec 12 '14 at 16:19
  • It is usually the same of js plugin file but not always. In fact, you can set whatever you want as name. The only thing you must know that this name is used to handle the script enqueue. I recommend to use the exact name given by the plugin developer. – cybmeta Dec 12 '14 at 18:17
  • I had tried 'tiny' (filename), 'zbdo', 'Zotonic Inline Text Direction Plugin', 'ZotonicBdoPlugin' as plugin names (these found in plugin) but its not working. Visual Editor completely goes blank & un-editable. Whats wrong? – John Doe Dec 13 '14 at 10:21
  • This code works. I've tested it. See the edited answer with my example test. The plugin is correctly added to TinyMCE, that doesn't mean that the TinyMCE plugin works correctly. It is correctly loaded but if it doesn't work you have to talk with the plugin developer as there is nothing we can do here with his/her work. – cybmeta Dec 13 '14 at 10:42
  • you are right. But I still not understand, when I remove '/' from '/editor_plugin.js', it will remove all things of editor? Why? – John Doe Dec 13 '14 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.