Hide the Node Title on a Page (6.x)

Last modified: August 27, 2009 - 00:22

Hide Node Title by Content Type

You can hide node titles by specific content type by adding some code to your template.php file.

This example ignores the title on any node that is of the type "page" or "story". Note that it also saves the title to another variable for use in other parts of the page.tpl.php if desired. Also note that these instructions cover the case where the function in question doesn't exist. If you get an error that says "cannot redeclare function ...", then you need to add the code to the existing function. Finally, you may have to go to admin/build/themes and save the themes form there to rebuild the theme registry before the changes take affect.

<?php
function THEMENAME_preprocess_page(&$vars) {

 
// Titles are ignored by content type when they are not desired in the design.
 
$vars['original_title'] = $vars['title'];
  if (!empty(
$vars['node']) && in_array($vars['node']->type, array('page', 'story'))) {
   
$vars['title'] = '';
  }

}
?>

To use the above code, replace 'page', 'story' with the node types which should have no titles and replace THEMENAME with the name of your theme. e.g. if your theme was named “foo”, the function would be named foo_preprocess_page. If your template.php file already has a THEMENAME_preprocess_page function, just add the lines of code inside your existing function.

Hide Node Title on Front Page

Here is an example of a way to accomplish this only on the front page. Again, this goes in your theme’s template.php file.

<?php
function THEMENAME_preprocess_page(&$vars) {

 
// Titles are ignored on the front page.
 
$vars['original_title'] = $vars['title'];
  if (
$vars['is_front']) {
   
$vars['title'] = '';
  }

}
?>

To use the above code, replace THEMENAME with the name of your theme. e.g. if your theme was named “foo”, the function would be named foo_preprocess_page. If your template.php file already has a THEMENAME_preprocess_page function, just add the lines of code inside your existing function.

 
 

Drupal is a registered trademark of Dries Buytaert.