• 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

    (@gwin)

    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

    (@pmmungai86)

    Hi Greg,

    The code can’t save, there is an error, kindly check.

    https://pasteboard.co/hX5Vkgdr0DTa.jpg

    Plugin Author Greg Winiarski

    (@gwin)

    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.