How to Limit the Title Length for Content Type in Drupal

Drupal's PHP editor lets you change the programming back-end of your blog. If you are familiar with the PHP language, you can customize the way Drupal interfaces with your users. If you want to limit the length of title input, edit the PHP code for your editor and set the maxlength characters to the number you want to use. Typically, a title tag is set to no more than 100 characters for blog posts.

Instructions

    • 1

      Open a Web browser and log into your Drupal dashboard. Click the Editor link and open the PHP page you want to edit.

    • 2

      Set the current maximum length for the title. The following code sets the $max variable to 100 characters:

      $max = variable_get('title_max_length_'.$node->type, 100);

    • 3

      Apply the maximum length to your title input and return an error if a title is longer than the $max length (100 in this example):

      if (strlen(trim($form['values']['title'])) > $max) {
      form_set_error('title', t('The title must be 100 characters or less.', array('%num' => $max)));

    • 4

      Save the changes and open the post editor in a separate browser. Enter a title longer than your $max length to ensure that the error message displays.

Related Searches:

References

Comments

Related Ads

Featured