Skip navigation

HOWTO: add headings tinymce plugin to WYSIWYG

The WYSIWYG module does a great job of centralizing and abstracting the use of various graphical editors in Drupal. Its relative newness means it is poorly and confusingly documented in some respects. I recently had to add the headings plugin for TinyMCE and ran into a lot of confusing information about how to make that happen.

My solution, and the recommended approach, is to use the hook_wywiwyg_plugin() API in a custom module to make the plugin available to WYSIWYG. There were a lot of contradictory examples of the code out there. This is what wound up working for me. Note that I installed the heading plugin in the tinymce plugins directory under sites/all/libraries.

/**
* Implementation of hook_wywiwyg_plugin().
*/
function FOOBAR_wysiwyg_plugin($editor, $version=0) {
  $plugins = array();
  switch ($editor) {
    case 'tinymce':
      if ($version > 3) {                      
          $plugins['heading'] = array(
          'type' => 'external',
          'title' => t('Headings'),
          'description' => t('Provides H1-H6 buttons for tinyMCE'),
          'path' => wysiwyg_get_path($editor) . '/jscripts/tiny_mce/plugins/heading/editor_plugin.js',
          'buttons' => array(
            'h1' => t('H1'),
            'h2' => t('H2'),
            'h3' => t('H3'),
            'h4' => t('H4'),
            'h5' => t('H5'),
            'h6' => t('H6'),
           ),
           'url' => 'http://sourceforge.net/tracker/index.php?func=detail&aid=1467705&group_id=103281&atid=738747',
           'load' => TRUE,
        );                     
      }
      break;
  }
  return $plugins;
}

Almost works

This helped a lot. I haven't created Drupal modules before but I found another guide for that which led me to the following steps.

Create the folder with the new module name (in my case tinymce_heading), create tinymce_heading.info, create tinymce_heading.module, and fill it with your code above. Replace FOOBAR with my module name (resulting in tinymce_heading_wysiwyg_plugin).

I enabled the module, went into my input format settings and added the newly available h2 and h3 buttons (the only ones I needed to use), and they showed up on the input field next time I checked.

Only problem is, they don't do anything. You can click 'em all you want, nothing happens.

I do have editor_plugin.js in /library/jscripts/tiny_mce/plugins/heading/

Think it's just a path issue?

HUGZ!!

Thank you SO much for this! I was most of the way to this implementation, but decided to give a more thorough look at the google results, and so found this. TOTALLY saved me hours!!

Thank you for this, I have

Thank you for this, I have been having lot of issues with tinymce and header buttons. As soon as I turned the inbuilt heading dropdown list it seems to bitch an strip lot of other tags from the content (footnote etc)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.