Created
August 24, 2015 13:53
-
-
Save shizhua/e75a0083b6734549a18d to your computer and use it in GitHub Desktop.
Add a Character Counter to Excerpt box
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
<?php | |
/** | |
* Add a Character Counter to Excerpt box | |
* URL: http://wpsites.org/?p=10503 | |
*/ | |
function excerpt_count_js(){ | |
echo '<script>jQuery(document).ready(function(){ | |
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:5px;right:80px;color:#666;\"><small>Excerpt length: </small><input type=\"text\" value=\"0\" maxlength=\"3\" size=\"3\" id=\"excerpt_counter\" readonly=\"\" style=\"background:#fff;\"> <small>character(s). (128 Characters MAX)</small></div>"); | |
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); | |
jQuery("#excerpt").keyup( function() { | |
jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); | |
if ( jQuery("#excerpt_counter").val() >= 101 ) { | |
jQuery("#excerpt_counter").css("color","red"); | |
} else { | |
jQuery("#excerpt_counter").css("color","green"); | |
} | |
}); | |
});</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