Limit the Excerpt field in WP-Admin in words

Is it possible to limit the Excerpt field on the post page in words? Note that I am aware that it’s possible to echo the excerpt and limit it in words, but I want the field itself to limit the amount of words, similar to how character limits on text-areas work.

Is such thing possible? Maybe a Javascript solution? Maybe something similar to what this plugin does to the character bio field (although its limitation is based on amount of characters).

Read More

The reason of this is that I run a multiple author platform where users often make the mistake to exceed the word limit that is being printed in the list of posts.

Related posts

Leave a Reply

1 comment

  1. You can use something like jQuery Simply Countable plugin and attach it to excerpt input.

    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 there is also word-count.js in WP core, but I can’t make sense if it’s as easy to use for blocking stuff.