Using WordPress ‘minimum_site_name_length’ PHP filter

minimum_site_name_length is a WordPress PHP filter that allows you to modify the minimum site name length required when validating a site signup.

Usage

add_filter('minimum_site_name_length', 'your_custom_function_name');
function your_custom_function_name($length) {
  // your custom code here
  return $length;
}

Parameters

  • $length (int) – The minimum site name length. Default is 4.

More information

See WordPress Developer Resources: https://developer.wordpress.org/reference/hooks/minimum_site_name_length/

Examples

Increase Minimum Site Name Length

Increase the minimum site name length to 6 characters.

add_filter('minimum_site_name_length', 'increase_minimum_site_name_length');
function increase_minimum_site_name_length($length) {
  $length = 6;
  return $length;
}

Decrease Minimum Site Name Length

Decrease the minimum site name length to 2 characters.

add_filter('minimum_site_name_length', 'decrease_minimum_site_name_length');
function decrease_minimum_site_name_length($length) {
  $length = 2;
  return $length;
}

Set Minimum Site Name Length Based on User Role

Set the minimum site name length to 3 for subscribers and 5 for all other user roles.

add_filter('minimum_site_name_length', 'set_minimum_site_name_length_based_on_role');
function set_minimum_site_name_length_based_on_role($length) {
  if (current_user_can('subscriber')) {
    $length = 3;
  } else {
    $length = 5;
  }
  return $length;
}

Remove Minimum Site Name Length Requirement

Remove the minimum site name length requirement by setting it to 1.

add_filter('minimum_site_name_length', 'remove_minimum_site_name_length_requirement');
function remove_minimum_site_name_length_requirement($length) {
  $length = 1;
  return $length;
}

Set Minimum Site Name Length Dynamically

Set the minimum site name length based on a value stored in a custom option.

add_filter('minimum_site_name_length', 'set_minimum_site_name_length_dynamically');
function set_minimum_site_name_length_dynamically($length) {
  $custom_length = get_option('custom_minimum_site_name_length');
  if ($custom_length) {
    $length = $custom_length;
  }
  return $length;
}