RSS

Newsletter

The CodeKarate Newsletter is the best way for technical ninjas to keep their swords sharpened. Don't worry, we won't flood your inbox and your email address will always remain private.
Back to Top

Hiding page titles for specific node types in Drupal 6

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'] = '';
}

Discussions

1
Anonymous

Hide specific page titles

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.

1-1
shane

A few options

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.

shane's picture
2
ashoksharma (not verified)

Name of Node type for Page

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?

2-1
shane

Drupal 6 or Drupal 7

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,

shane's picture
2-2
Adam Learing (not verified)

Drupal 7 Page Titles

Shane -

Could you please post a solution for hiding page titles in Drupal 7. Thanks.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <php>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <python>, <ruby>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.