Created
October 27, 2012 14:59
-
-
Save WebEndevSnippets/3965000 to your computer and use it in GitHub Desktop.
WordPress: Add Manual Excerpt Word Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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