Custom html.tpl.php template by content type

You can overwrite your default html.tpl.php file for individual content types by using this approach. This can be useful if you are trying to do something like change the entire site layout for a particular content type.

Say you've created a new content type called: My Content Type. This will have the machine name my_content_type.

  1. Make a copy of your default html.tpl.php file in your /sites/all/themes/themename/templates folder.
  2. Rename this file to html--my_content_type.tpl.php - note the use of the underscores which is different to naming a node--my-content-type.tpl.php file!
  3. Add the below code to your themes template.php file, replacing the 'themename' & 'my_content_type' values for your own.
  4. Flush the cache to see your html.tpl.php template overwrite in effect.
function themename_preprocess_html(&$vars) {   
	$node = menu_get_object();
	if ($node && $node->nid) {
		$vars['theme_hook_suggestions'][] = 'html__' . $node->type;


Justin Chevallier

Justin Chevallier

Avid Drupal site builder & user for +10 years.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.