Title: Restrict input length
Last modified: April 28, 2018

---

# Restrict input length

 *  Resolved [wiltschek](https://wordpress.org/support/users/wiltschek/)
 * (@wiltschek)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/restrict-input-length/)
 * Hi,
 * this is a great plugin!
    I noticed that MailChimp cuts off text at 255 characters.
   So I’d like to limit the text users can write to 255 characters, so they at least
   know that it won’t be seen.
 * How would I go about doing this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [yikesitskevin](https://wordpress.org/support/users/yikesitskevin/)
 * (@yikesitskevin)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/restrict-input-length/#post-10231878)
 * Hi [@wiltschek](https://wordpress.org/support/users/wiltschek/),
 * Using a filter, you can add a maxlength attribute to your text fields which will
   force the input to be 255 characters or shorter.
 * This filter function will do that:
 *     ```
       // Add a maxlength to an input field
       add_filter( 'yikes-mailchimp-field-data', 'yikes_easy_forms_text_field_max_length', 10, 3 );
   
       function yikes_easy_forms_text_field_max_length( $field_array, $field, $form_id ) {
       	if ( $field['type'] === 'text' ) {
       		$field_array[] = 'maxlength="255"';
       	}
   
       	return $field_array;
       }
       ```
   
 * Will that work for you?
 * Let me know.
 * Cheers,
    Kevin.
 *  Thread Starter [wiltschek](https://wordpress.org/support/users/wiltschek/)
 * (@wiltschek)
 * [8 years, 1 month ago](https://wordpress.org/support/topic/restrict-input-length/#post-10234747)
 * Works like magic! Thanks a lot!
 * For people who don’t know how to use filters… I used [https://wordpress.org/plugins/code-snippets/](https://wordpress.org/plugins/code-snippets/)
   and just copied the above code into a new snippet, and then added the “short 
   code” for the snippet on the page.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Restrict input length’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/yikes-inc-easy-mailchimp-extender_a1c7e5.
   svg)
 * [Easy Forms for Mailchimp](https://wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/yikes-inc-easy-mailchimp-extender/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/yikes-inc-easy-mailchimp-extender/)
 * [Active Topics](https://wordpress.org/support/plugin/yikes-inc-easy-mailchimp-extender/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/yikes-inc-easy-mailchimp-extender/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/yikes-inc-easy-mailchimp-extender/reviews/)

## Tags

 * [input](https://wordpress.org/support/topic-tag/input/)
 * [maxlength](https://wordpress.org/support/topic-tag/maxlength/)

 * 2 replies
 * 2 participants
 * Last reply from: [wiltschek](https://wordpress.org/support/users/wiltschek/)
 * Last activity: [8 years, 1 month ago](https://wordpress.org/support/topic/restrict-input-length/#post-10234747)
 * Status: resolved