Title: Title Problem
Last modified: October 19, 2021

---

# Title Problem

 *  [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * (@pmmungai86)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/title-problem-22/)
 * Hi Greg,
 * Do you have a snippet I can use to limit title characters to 25?
    Users having
   a title of 50 or 80 characters is really messing up everything, please.

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

 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/title-problem-22/#post-14987658)
 * Hi,
    sure, you can limit the maximum number of characters in the title either
   with the Custom Fields extension or by adding the code below in your theme functions.
   php file
 *     ```
       add_filter( "adverts_form_load", "limit_title_length" );
       function limit_title_length( $form ) {
         if( $form['name'] != "advert" ) {
           return $form;
         }
         foreach( $form["field"] as $key => $field ) {
           if( $field["name"] == "post_title" ) {
               $form["field"][$key]["validator"][] = array(
                   "name" => "string_length",
                   "params" => array( "min" => 5, "max" => 25 )
               );
           }
         return $form;
       }
       ```
   
 *  Thread Starter [pmmungai86](https://wordpress.org/support/users/pmmungai86/)
 * (@pmmungai86)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/title-problem-22/#post-14987941)
 * Hi Greg,
 * The code can’t save, there is an error, kindly check.
 * [https://pasteboard.co/hX5Vkgdr0DTa.jpg](https://pasteboard.co/hX5Vkgdr0DTa.jpg)
 *  Plugin Author [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * (@gwin)
 * [4 years, 7 months ago](https://wordpress.org/support/topic/title-problem-22/#post-14991449)
 * Hi,
    sorry, there is a typo in the code, please try this instead
 *     ```
       add_filter( "adverts_form_load", "limit_title_length" );
       function limit_title_length( $form ) {
         if( $form['name'] != "advert" ) {
           return $form;
         }
         foreach( $form["field"] as $key => $field ) {
           if( $field["name"] == "post_title" ) {
               $form["field"][$key]["validator"][] = array(
                   "name" => "string_length",
                   "params" => array( "min" => 5, "max" => 25 )
               );
           }
         }
         return $form;
       }
       ```
   

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

The topic ‘Title Problem’ is closed to new replies.

 * ![](https://ps.w.org/wpadverts/assets/icon-256x256.png?rev=2423472)
 * [WPAdverts - Classifieds Plugin](https://wordpress.org/plugins/wpadverts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpadverts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpadverts/)
 * [Active Topics](https://wordpress.org/support/plugin/wpadverts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpadverts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpadverts/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Greg Winiarski](https://wordpress.org/support/users/gwin/)
 * Last activity: [4 years, 7 months ago](https://wordpress.org/support/topic/title-problem-22/#post-14991449)
 * Status: not resolved