Skip to content

Instantly share code, notes, and snippets.

@FernE97
Last active October 9, 2015 18:47
Show Gist options
  • Save FernE97/3558873 to your computer and use it in GitHub Desktop.
Save FernE97/3558873 to your computer and use it in GitHub Desktop.
PHP: WP excerpt character counter
<?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