Home Forums Plugin Support WP User Frontend (Free Version) Setting word limit for excerpt

This topic is: resolved

This topic contains 4 replies, has 3 voices, and was last updated by  MDelcour 4 years ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #9958

    gpspake
    Participant
    Post count: 14

    I need to set a word count limit for the excerpt so users can't type more than 40 words in the excerpt. Do I need to create a new custom text area type that can be used in addition to ‘Normal,' ‘Rich' and ‘Teeny Rich'?

    #9959

    Tareq Hasan
    Keymaster
    Post count: 2831

    This kind of functionalities doesn't work in rich or teeny textareas, but works fine in normal textarea. Take a look at this tutorial achieving this.

    #9970

    gpspake
    Participant
    Post count: 14

    Perfect. I'm going to try this out; I'll report back with results. Thanks.

    #10019

    gpspake
    Participant
    Post count: 14

    Ok, I'm back and that worked perfectly. I took it a step farther and added a character count in the help text by adding a line to the example jQuery. Now, in addition to the character limit, user see how many characters they have left. feel free to add this to the example doc as it is already very useful.

    Help text:
    Brief description to describe the post. <span class="excerpt-char-count">400</span> characters remaining.

    jQuery

    //Text Limit for WPUFE
    function wpufe_limit_text() {
       
      if ( is_page('test') ) {
    		?>		
    	    <script type="text/javascript">
    	        (function($) {
    	 
    	            function limitText(field, maxChar){
    	                var ref = $(field),
    	                    val = ref.val();
    	 
    	                if ( val.length >= maxChar ) {
    	                    ref.val(val.substr(0, maxChar));
    	                }
    	            }
    	 
    	            // Insert Limitations here
    	            $('#post_excerpt').on('keyup', function(event) {
    	                limitText(this, 400);
    	                $( ".excerpt-char-count" ).html( 400 - $(this).val().length );	                
    	            });
    
    	        })(jQuery);
    	    </script>
    		<?php
    	}
    }
    add_action( 'wp_footer', 'wpufe_limit_text' );
    #41320

    MDelcour
    Participant
    Post count: 46

    You're a LEGEND!! Great solution

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Setting word limit for excerpt’ is closed to new replies.