There is a plugin for the ckeditor module that allows for a word count function:
#764014: Word Count Plugin

Can we get it so this works with ckeditor in wysiwyg module?
How can I help towards achieving this?


TwoD’s picture

Category: feature » support

We will most likely not include direct support of 3rd party plugins in Wysiwyg itself, we've wouldn't have time to keep up with them all.

Instead, Wysiwyg has a hook for describing editor plugins called hook_wysiwyg_plugins(). It's described in wysiwyg.api.php and all you need to do is to implement it in a small Drupal module, like this:

name = My tweaks
core = 7.x


function MYMODULE_wysiwyg_plugin($editor, $version) {
  switch ($editor) {
    case 'ckeditor':
      return array(
        'wordcount' => array( // Internal plugin name
          'extensions' => array(
            'wordcount' => t('Word count'), // Internal plugin name as key, name visible in editor profile config UI as value.
          'load' => TRUE,
          'internal' => FALSE,
          'path' => wysiwyg_get_path('ckeditor_plugins') . '/wordcount',

Then extract the plugin to sites/all/libraries/ckeditor_plugins/wordcount.
That will make Wysiwyg put a "Word Count" checkbox in the "Buttons and Plugins" list and include the plugin when the checkbox is checked. I put the plugin outside the CKEditor path and point there using the 'path' key above so I can upgrade CKEditor without worrying about reinstalling the plugin. However, there's a chance the plugin might not tolerate this (it can use relative paths to refer to CKEditor's files etc), so you can place it in the ckeditor/plugins path if you also remove the above 'path' key and switch the 'internal' key to TRUE.

Now, this plugin also uses a new element to actually show the word limit in. You could probably add that using hook_form_alter(), making sure it begins with the same name as the field, to all fields where you need it. That might get troublesome in the long run, so it might be better to implement hook_element_info(), add another '#pre_render' callback to the 'text_format' element type and injects the hidden field from there. Looking through wysiwyg_pre_render_text_format() should give you some hints to when and how Wysiwyg determines when to include the editor code, in case you don't want the hidden field to show up when it's not going to be used.

Also note that a couple of bugs in this plugin have been mentioned over at so it might not work as expected when there are multiple editors on the page or when instances are removed.

Murz’s picture

Also you can look to my version of character counter plugin:

TwoD’s picture

Status: Active » Fixed

Closing this as "fixed" to clean up the queue a bit. Please change back to "active" if you encounter problems.

yanniboi’s picture

No problem @TwoD. Thanks for the advice!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ggevalt’s picture

Thanks so much for your effort on this...
Do you have a wysiwyg 6.x version of this?
Thanks so much in advance,