Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save juniovitorino/c4f11d92a28fcd6fefd2 to your computer and use it in GitHub Desktop.
Save juniovitorino/c4f11d92a28fcd6fefd2 to your computer and use it in GitHub Desktop.

Revisions

  1. raewrites renamed this gist Feb 25, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. raewrites created this gist Feb 25, 2015.
    19 changes: 19 additions & 0 deletions excerpt-character-counter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function excerpt_count_js(){

    if ('page' != get_post_type()) {

    echo '<script>jQuery(document).ready(function(){
    jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><small>Excerpt length: </small><span id=\"excerpt_counter\"></span><span style=\"font-weight:bold; padding-left:7px;\">/ 500</span><small><span style=\"font-weight:bold; padding-left:7px;\">character(s).</span></small></div>");
    jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);
    jQuery("#excerpt").keyup( function() {
    if(jQuery(this).val().length > 500){
    jQuery(this).val(jQuery(this).val().substr(0, 500));
    }
    jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);

    });
    });</script>';
    }
    }
    add_action( 'admin_head-post.php', 'excerpt_count_js');
    add_action( 'admin_head-post-new.php', 'excerpt_count_js');