Hiding page titles for specific node types in Drupal 6

By shane
Tue, 2011-07-12 10:39
5 comments

Share with Others

Occasionally you may need to hide a page title in Drupal 6 for a number of reasons. This can be especially useful if you are theming a node page and want to display the page title somewhere else in the node content. I often need to use this when theming Ubercart product pages. It is really very simple to do, just add this function to your template.php file inside your theme.

function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('NODETYPE'))) {
    $vars['title'] = '';
  }
}

You can easily replace THEMENAME with the name of your theme and NODETYPE with the type of node you want to hide the title for. You can add multiple node types to the array if you need to hide the title for more than one type of node. If you want to globally hide the page titles you can use this code.

function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  $vars['title'] = '';
}

Comments

Thanks for the post. I was wondering how you can hide just one page title for a specific node type. For example, if I don't want to show the page title on only the home page.

There are a few options that I can think of that would work. The first would be adding something similar to this to your page.tpl.php file:

if ( $is_front ) {
  unset($title);
}

One other option that would probably work would be to add this to your THEMENAME_preprocess_page function in your template.php file. I have not tested this yet, but it should be pretty close.

function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if ($vars['is_front']) {
    $vars['title'] = '';
  }
}

Let me know if that works for you.

Thanks
I need the same thing

I want to hide Title for my content type 'Page' I simply replaced the NODETYPE with page but its not working. Showing the error if I try to save a page without the code

Am I doing wrong?

Are you using Drupal 6 or Drupal 7. Drupal 7 handles this slightly differently. If you are using Drupal 6, paste your code and I will see if I can determine the problem. If you are using Drupal 7, let me know and I can post a solution for that too.

Thanks,

Post new comment