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.

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.

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.

Comments

lostcarpark’s picture

Thanks for this handy tip.

This is very close to what I want, but I also wanted to remove the node title from the TITLE tag, so that rather than "Node Title | Site Name" I just get "Site Name".

This is how I did it:

function THEMENAME_preprocess_page(&$vars, $hook) {
  // Titles are ignored on the front page.
  $vars['original_title'] = $vars['title'];
  if ($vars['is_front']) {
    $vars['title'] = '';
    $vars['head_title'] = variable_get('site_name', 'Drupal');
  }
}
P2790’s picture

For drupal 7 the following code worked for me:

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

I just removed the first line:

$vars['original_title'] = $vars['title'];

However I do not know what this did!

wooody’s picture

Thanks , Works with me.. for sure it's need to clear cache to work fine
Regards

deeve’s picture

I must admit to being completely baffled by some of D7's basic structure; I need to use several static pages as well as a database of searchable content. For the static pages I'm using the Basic Page node type, but this requires a Title to be entered, which I can understand is useful in Admin but do not need this to appear on the website. I thought this thread would solve my problem but doesn't appear to have had any effect or thrown a critical error. I also tried filtering the Title out of a 'View' for my front page but this didn't work either.

Any other suggestions?

mengi’s picture

I'm looking into this also. I'm using Drupal 7 and this doesn't seem to be working for me either. I thought since I'm using a sub-theme, maybe my sub's template.php is being overwritten by the parent theme, but I change the parent's template.php and still didn't work.

For a quick fix, you can add;

#main #page-title {
display:none }

to your themes CSS.
or
go into your themes page.tpl.php file and remove:

<?php if ($title): ?>
        <h1 class="title" id="page-title"><?php print $title; ?></h1>
      <?php endif; ?>
      <?php print render($title_suffix); ?>>

this will remove all titles for all content types I believe.

I will post again once I found out the best solution. GL

ihsanfaisal’s picture

try to use this module. simple but functional
http://drupal.org/project/exclude_node_title

bojans’s picture

I installed it and it works fine. There are several options for removing title on particular content type or individual node. Thanks!