Last active
October 9, 2015 18:47
-
-
Save FernE97/3558873 to your computer and use it in GitHub Desktop.
PHP: WP excerpt character counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Excerpt character count | |
function excerpt_count_js() { ?> | |
<script> | |
jQuery(document).ready(function ($) { | |
var counterVal = $('#excerpt-counter input').val($('#excerpt').val().length); | |
$('#postexcerpt .handlediv').after('<div id="excerpt-counter"><small>Excerpt length: </small> <input type="text" value="0" maxlength="3" size="1" readonly> <small>character(s)</small></div>'); | |
counterVal | |
$('#excerpt').on('keyup', function () { | |
counterVal | |
}); | |
}); | |
</script> | |
<style> | |
#excerpt-counter { | |
position: absolute; | |
top: 2px; | |
right: 30px; | |
color: #666; | |
} | |
#excerpt-counter input { | |
background: #f2f2f2; | |
} | |
</style> | |
<?php | |
} | |
add_action( 'admin_head-post.php', 'excerpt_count_js' ); | |
add_action( 'admin_head-post-new.php', 'excerpt_count_js' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment