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;
}
Hi Greg,
The code can’t save, there is an error, kindly check.
https://pasteboard.co/hX5Vkgdr0DTa.jpg
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;
}