Skip to content

Mstoic

  • Home
  • Start Here!
  • Best Deals
  • Facebook Tricks
  • Privacy
  • Resources
  • TOC
  • Tools
    • Web Tools
      • Stop Watch
      • QR Code Generator
      • Adsense Code Converter
      • Blogger Sitemap Generator
      • Difference Between Two Texts
      • Vacation Checklist
      • Twitter Symbols
      • Count Down
    • Investment
      • SIP Calculator
      • Power of Compounding
      • PPF Calculator
      • FD Calculator
  • About Us

Add Character Counter To Excerpt Box In WordPress

Editorial Team | February 4, 2015February 4, 2015 | Wordpress |

WordPress displays a nice word counter below the post content area to let you know how long the post you are working on is. But it has no such counter for the excerpt area.

If you are somewhat into the SEO field then you would know that having the excerpt long enough is not good from SEO perspective. Some Search Engine specialist suggest that you should have your post excerpt 130-160 letters long. If it goes beyond 160, you are giving away too much description that will not fit in search engine’s description area.

Related Articles

  • Optimizing Database For WordPress Websites Automatically [Free Plugin]
  • 22 Things To Do For A Faster WordPress Website
  • 4 Ways To Enable Gzip Compression In WordPress
  • How to Edit .htaccess File from WordPress Dashboard Itself
  • Google Authenticator for WordPress

But counting excerpt length manually is again a huge problem, and using some other text editor is again time-consuming. To make this process easier, we have a small snippet, which when added to “functions.php“, displays a letters counter above the excerpt meta box.

excerpt-character-counter

The counter will automatically turn red if you exceed the character limit of 160 characters. It won’t trim your excerpt, but is just an indication that you are exceeding the suggested character limit.

function excerpt_count_js() {   echo '<script>     jQuery(document).ready(function() {       jQuery("#postexcerpt .inside").prepend("<div style=\"margin: 5px 0;\" color:#666;\"><small>Letter Count: <span style=\"font-weight:bold; padding: 0 5px;\" id=\"excerpt_counter\"></span></small></div>");       jQuery("#excerpt_counter").val(jQuery("#excerpt").val().length);       jQuery("#excerpt").keyup( function() {         excerpt_color();       });     excerpt_color();   }); function excerpt_color() {   jQuery("#excerpt_counter").html(jQuery("#excerpt").val().length);   if ( parseInt(jQuery("#excerpt_counter").html()) >= 160 ) {     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');
Previous Post

5 Most Popular YouTube Easter Eggs That Still Work

by Editorial Team

Next Post

Display Page Load Time in WordPress Without Plugin

by Editorial Team

Recommended Next
Auto Update Plugins And Themes In WordPress

Your Comment Cancel reply

Follow Us

Like us Follow us Follow us

Categories

  • Tricks (93)
  • Facebook (83)
  • Tips (76)
  • Windows (67)
  • Wordpress (39)
  • Android (38)
  • Internet (33)
  • Antivirus (30)
  • How To (29)
  • Webmasters (25)
  • Customization (25)
  • Downloads (21)
  • Utilities (21)
  • Gmail (20)
  • Windows 7 (19)

Related Articles

  • Reverse a String using StringBuilder