Automatically Generating Node Titles in Drupal

media_1352773828770.png

It’s fairly common to replace the title field in Drupal.

There are many possible reasons to replace the title, but most of them come down to this … the title field is not very flexible.

To take just one example, imagine that you’re adding a directory of your staff members to your site. Presumably, you’d like the person’s name to be the title of each page. However, because the title field only consists of a text field with 255 characters, you can’t have close control over what people enter. The solution is to replace the default title with specific “First Name” and “Last Name” fields.

So, here’s how to automatically generate titles in Drupal 7.

media_1352773828770.png

Step 2: Set Up Each Content Type

  • Go to Structure > Content types
  • Look for the automatic title generation area as in the image below
  • You’ll be able to use tokens to automatically replace the title

media_1352774012751.png
  • In the example below, we’re completely hiding the title field. If we choose the bottom radio button, the title field would be available to users and our tokens would only work if the title field isn’t used.
  • In the image below, we’re automatically replacing the title with the First name and Last name fields.

media_1352774943444.png

Step 3: Create the Content

  • Click Add content and create an example of your content type
  • Notice that the title field is completely missing

media_1352775119615.png
  • Save the content and your title will be automatically generated:

media_1352775267754.png

Author

  • Steve Burge

    Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.

0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
JobotBobica
JobotBobica
11 years ago

Auto Entity Label is the newer version of auto node title, so that is the prefered module to use:

[url=http://drupal.org/project/auto_entitylabel]http://drupal.org/project/a…[/url]

Inzzi
Inzzi
11 years ago

That works great. I was able to create a new rule through the interface and it worked when I tested it. I just put dummy data in the title field so I could submit since it was a required field. Once the product was saved, my dummy data had been overwritten with the SKU on mys site: [url=http://www.kamagra.com.mx]http://www.kamagra.com.mx[/url] . I will deal with the hook_form_alter and the concatenation of the SKU and the other field tomorrow. The other filed is a taxonomy term. This is all so new to me, but I am beginning to recognize how powerful it is. Thank you so much for your help.

♥Queen Barbie♥
♥Queen Barbie♥
10 years ago

Thanks for the tutorial however I used the random number “[random:number]” token and whenever I edit the node the title regenerates again how would i fix this as i want the title to remain the same no matter what changes of updates I perform on the node?

3
0
Would love your thoughts, please comment.x
()
x