Saturday, June 9, 2012

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


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:

  1. Daily Tip: Easily Change the Length of the Default WordPress Excerpt The default WordPress excerpt is 55 words long. By adding...
  2. Daily Tip: Replace Default WordPress Excerpt Ellipsis With Read More Link Add this to your functions.php file. It will replace the...
  3. Daily Tip: Make Use of the Screen Options Menu to Clean Up the WordPress Post Editor Choose which boxes show on the post editor page....

No comments:

Post a Comment

Search This Blog

Top WordPress Seller