Daily Tip: How to Add a Character Counter to the WordPress Excerpt Box |
Daily Tip: How to Add a Character Counter to the WordPress Excerpt Box Posted: 09 Jun 2012 07:00 AM PDT Here’s a handy little trick that I found over at wpsnipp.com recently. This snippet lets you add a character counter to the excerpt box on your post edit screen, as pictured below: You can add this to your functions.php file or create your own little plugin for it, if that’s what you prefer: function 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>character(s).</small></div>"); jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); jQuery("#excerpt").keyup( function() { jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length); }); });</script>'; } add_action( 'admin_head-post.php', 'excerpt_count_js'); add_action( 'admin_head-post-new.php', 'excerpt_count_js'); Why would you need a character counter on your excerpt box?Certainly it seems like a character counter is far more useful for the post content metabox. However, your active theme may have very specific requirements for how long your excerpts should be. If you want to be a perfectionist about your excerpts and don’t want to see them cut off with ellipses, then you’ll want to keep your excerpt length to a certain number of characters. This is where an excerpt character counter comes in handy. Add this little code snippet if you want to try to keep your excerpts unbroken or a bit more uniform. Many thanks to Kevin Chard for posting the code over at wpsnipp.com. Related posts:
|
You are subscribed to email updates from The WordPress Experts - WPMU.org To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
No comments:
Post a Comment