This code counts the number of words in an excerpt and adds it to the excerpt meta box in the post edit screen: http://snippi.com/s/sn3hk5p

However, something about this code is preventing the editing of permalinks in the post edit screen and I am unable to identify the problem. Any ideas?

1 Answer 1


I put the script in a external file

// Excerpt word count
function excerpt_count_js(){
    wp_enqueue_script( 'excerpt-word-count', plugins_url( 'excerpt_word_count.js', __FILE__ ), array( 'jquery' ), false, true );

And modified the script a bit

        $("#postexcerpt .handlediv")
        .after("<div style=\"position:absolute;top:2px;right:5px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>word(s).</small></div>");

        $("#excerpt_counter").val($("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);

            function() {
                $("#excerpt_counter").val( $("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);

Finally change the hook for loading the script

add_action( 'load-post.php', 'excerpt_count_js');
add_action( 'load-post-new.php', 'excerpt_count_js');

No problems at all.

Just to clearify: with 'permalinks', did you mean the permlink of the post (the line between title input and content input) ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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