On my site, I have several content types. They all use the same node--content_type.tpl.php file. However, the mark up applied to the node title has to change depending on the content type.

How can I modifying the title according to the content type from template.php?

(I don't want to use too many IF statements in my node.tpl.php file as you are supposed to keep those files clean, so I want the code to go in my template.php file).

(This question is for Drupal 7).

2 Answers 2


I found the solution to this

  1. Create a field called Title

  2. Your users use this new field to enter a title

  3. Use Auto Node Title to automatically title the node based on this field.

You can ow hide the original title in your theme and use the new title filed instead. The new title field can be customised like a regular field.


You could use Display Suite to control the layout of your content type including how to visualize each field which includes the title, you will need to activate Display Suite Extras so you can control how to output each field. I think the field template could be your answer for this. You can find a demo and extra information in the following links:

This could be a good alternative if you don't want to use many if's statements in your tpl.

  • Thanks for taking the time to reply! I think Display Suite would be overkill. I only want to change the mark up for the title, ideally from template.php.
    – big_smile
    Nov 12, 2012 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.