Community Documentation

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

Last updated August 27, 2009. Created by JohnAlbin on April 7, 2009.
Edited by ronald_istos, robertDouglass. Log in to edit this page.

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.

Comments

Hiding from TITLE tag

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');
  }
}

For drupal 7

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!

Thanks , Works with me.. for

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

Baffled!

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?

.

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

http://drupal.org/project/exclude_node_title

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

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.