你可以使用jQuery Simply Countable plugin 并将其附加到摘录输入。
Limit_Excerpt_Words::on_load();
class Limit_Excerpt_Words {
static function on_load() {
add_action( \'admin_enqueue_scripts\', array( __CLASS__, \'admin_enqueue_scripts\' ) );
}
static function admin_enqueue_scripts() {
global $hook_suffix;
if ( \'post.php\' == $hook_suffix || \'post-new.php\' == $hook_suffix ) {
wp_enqueue_script( \'jquery-simply-countable\', plugins_url( \'/jquery.simplyCountable.js\', __FILE__ ), array( \'jquery\' ), \'0.4.2\', true );
add_action( \'admin_print_footer_scripts\', array( __CLASS__, \'admin_print_footer_scripts\' ) );
}
}
static function admin_print_footer_scripts() {
?>
<script type=\'text/javascript\'>
jQuery(document).ready(function ($) {
$(\'#excerpt\').simplyCountable({
countType:\'words\', maxCount:5, strictMax:true
});
});
</script>
<span id="counter" style="display:none;"></span><!-- needs counter to work -->
<?php
}
}
PS还有
word-count.js
在WP core中,但我无法理解它是否可以轻松地用于阻止内容。