Limit on the max number of words per post?

You can hide the submit button, if to much words on the editor. The Editor has an id and also the button; use an small JS to realized your requirement.
An example solution for the comment form can you find at the follow code and more infos on this post.

jQuery(function($) {
    // configure
    var comment_input = $( '#commentform textarea' );
    var submit_button = $( '#commentform .form-submit' );
    var comment_limit_chars = 1000;
    // stop editing here

    // display how many characters are left
    $( '<div class="comment_limit_info"><span>' + comment_limit_chars + '</span> characters left</div>' ).insertAfter( comment_input );

    comment_input.bind( 'keyup', function() {
        // calculate characters left
        var comment_length = $(this).val().length;
        var chars_left = comment_limit_chars - comment_length;

        // display characters left
        $( '.comment_limit_info span' ).html( chars_left );

        // hide submit button if too many chars were used
        if (submit_button)
            ( chars_left < 0 ) ? submit_button.hide() : submit_button.show();
    });
});

Change the IDs and classes for use the source on the editor-field. But the example count the strings, not the word; but you can count words if you count the spaces. The follow example doing this; but you must change the form_name; its the name attribut of the element, the editor-textarea or iframe.

function countWords(){
    document.form_name.wordcount.value = document.form_name.inputString.value.split(' ').length;
}

Leave a Comment