Skip to content

Instantly share code, notes, and snippets.

@WebEndevSnippets
Created October 27, 2012 14:59
Show Gist options
  • Save WebEndevSnippets/3965000 to your computer and use it in GitHub Desktop.
Save WebEndevSnippets/3965000 to your computer and use it in GitHub Desktop.
WordPress: Add Manual Excerpt Word Counter
add_action( 'admin_head-post.php', 'we_excerpt_count_js' );
add_action( 'admin_head-post-new.php', 'we_excerpt_count_js' );
/**
* Add Manual Excerpt Word Counter in Posts
*
*/
function we_excerpt_count_js() {
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:0px;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>");
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);
jQuery("#excerpt").keyup( function() {
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().split(/\S+\b[\s,\.\'-:;]*/).length - 1);
});
});</script>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment