Created
February 25, 2015 06:09
-
-
Save raewrites/e9ac981ab1f55d386822 to your computer and use it in GitHub Desktop.
Excerpt Character Counter
This file contains hidden or 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
function excerpt_count_js(){ | |
if ('page' != get_post_type()) { | |
echo '<script>jQuery(document).ready(function(){ | |
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><small>Excerpt length: </small><span id=\"excerpt_counter\"></span><span style=\"font-weight:bold; padding-left:7px;\">/ 500</span><small><span style=\"font-weight:bold; padding-left:7px;\">character(s).</span></small></div>"); | |
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length); | |
jQuery("#excerpt").keyup( function() { | |
if(jQuery(this).val().length > 500){ | |
jQuery(this).val(jQuery(this).val().substr(0, 500)); | |
} | |
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length); | |
}); | |
});</script>'; | |
} | |
} | |
add_action( 'admin_head-post.php', 'excerpt_count_js'); | |
add_action( 'admin_head-post-new.php', 'excerpt_count_js'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment