Bambang pramusintha

How to Add a Character Counter to the WordPress Post Excerpt Box

In Excerpt Box, JQuery, Tutorial, Wordpress Tutorial on July 9, 2012 at 10:11 am

Why would you need a character counter on your excerpt box?

Certainly it seems like a character counter in WordPress post token is far more useful for the post content meta box. However, the active theme you may have very specific requirements for how long should your quote. If you want to be a perfectionist about your quote and do not want to see them cut the ellipse, then you will want to keep the length of your quotes to a certain number of characters. This is where the quote character counter will help.

Here is a handy little trick of wpsnipp.com recently. This piece counter lets you add character to the quote box on the screen edit your posts, as pictured below:

You can add this to your functions.php file or create your own little plugin for it :

function excerpt_count_js(){ echo ‘// <!–[CDATA[
jQuery(document).ready(function(){
jQuery(“#postexcerpt .handlediv”).after(”

Excerpt length: character(s).

“);
jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length);
jQuery(“#excerpt”).keyup( function() {
jQuery(“#excerpt_counter”).val(jQuery(“#excerpt”).val().length);
});
});
// ]]>’; } add_action( ‘admin_head-post.php’, ‘excerpt_count_js’); add_action( ‘admin_head-post-new.php’, ‘excerpt_count_js’);

Add a little piece of code if you want to try to keep the quote you get disconnected or a little more uniform. Many thanks to Kevin Chard for posting the code above in wpsnipp.com.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: