Title: Word Count JavaScript
Last modified: August 19, 2016

---

# Word Count JavaScript

 *  Resolved [michaelpark](https://wordpress.org/support/users/michaelpark/)
 * (@michaelpark)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/word-count-javascript/)
 * Hello,
 * I found the following JavaScript in my WordPress account for counting words as
   you type on the write screen, but I’ve no idea how to integrate it to my own 
   copy of WordPress on my domain.
 * The file is apparently named “wordcount.js-102007” or something close to that.
 * Any idea on how to use this???
 *     ```
       jQuery( function($) {
   
       	var w = $("<span class='wp-word-count'>" + wordCountL10n.count.replace( /%d/, "<span id='word-count'></span>" ) + "</span>").prependTo('#poststuff p.submit:first');
   
       	var block = 0;
       	var wc = function(text) {
       		if ( block ) return;
       		block = 1;
   
       		setTimeout( function() {
       			var t = $.trim(text);
       			var tc = '0';
       			if ( t ) {
       				t = ' ' + t.replace( /<.[^<>]*?>/g, '' ) + ' ';
       				tc = t.split( /\s[\s.(),;:!?'"_+=\\/-]*/ ).length - 2;
       				tc = tc.toString();
       			}
   
       			w.children('span')[0].innerHTML = tc;
   
       			setTimeout( function() { block = 0; }, 2000 );
       		}, 1 );
       	};
   
       	var fwc = function() {
       		var t =  parseInt(w.children('span').text()) + 1;
       		w.children('span').text( t.toString() );
       	};
   
       	var last = 0;
   
       	var co = $('#content').keyup( function(e) {
       		if ( e.keyCode == last )
       			return true;
       		if ( 13 == e.keyCode )
       			wc( co.val() );
       		else if ( 32 == last )
       			fwc();
       		last = e.keyCode;
       		return true;
       	} );
   
       	wc(co.val());
   
       	if ( 'undefined' == typeof TinyMCE_wordpressPlugin ) { return; }
       	var o = $.isFunction(TinyMCE_wordpressPlugin.handleEvent) ? TinyMCE_wordpressPlugin.handleEvent : function() { return true; };
   
       	TinyMCE_wordpressPlugin.handleEvent = function(e) {
       		if ( !o(e) )
       			return false;
       		if ( 'keyup' == e.type ) {
       			if ( e.keyCode == last )
       				return true;
       			if ( 13 == e.keyCode )
       				wc( tinyMCE.getInstanceById('content').getHTML() );
       			else if ( 32 == last )
       				fwc();
       			last = e.keyCode;
       		}
       		return true;
       	};
   
       } );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [michaelpark](https://wordpress.org/support/users/michaelpark/)
 * (@michaelpark)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/word-count-javascript/#post-668450)
 * Anyone?
 *  Thread Starter [michaelpark](https://wordpress.org/support/users/michaelpark/)
 * (@michaelpark)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/word-count-javascript/#post-668453)
 * [http://trac.wordpress.org/ticket/4807](http://trac.wordpress.org/ticket/4807)
 *  [Storyman](https://wordpress.org/support/users/storyman/)
 * (@storyman)
 * [18 years ago](https://wordpress.org/support/topic/word-count-javascript/#post-668552)
 * Michael,
 * Did you ever get it working?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Word Count JavaScript’ is closed to new replies.

## Tags

 * [count](https://wordpress.org/support/topic-tag/count/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [word](https://wordpress.org/support/topic-tag/word/)

 * 3 replies
 * 2 participants
 * Last reply from: [Storyman](https://wordpress.org/support/users/storyman/)
 * Last activity: [18 years ago](https://wordpress.org/support/topic/word-count-javascript/#post-668552)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
