Hiding Drupal 7 Page Titles using theme_preprocess_page

By shane
Wed, 2012-12-05 09:30
3 comments

Share with Others

I wrote a post on Hiding page titles for specific node types in Drupal 6, this is just an updated post for Drupal 7.

The code is essentially the same, but requires just a minor change. If you want to hide the page title on only the front page of your Drupal 7 website, add the following code to your themes template.php file (replacing THEMENAME with the name of your theme):

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

If you want to hide the page title for specific node types on your Drupal 7 website, add the following code to your template.php file (replacing THEMENAME with the name of your theme, and changing NODETYPE1 and NODETYPE2 to your node types):

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

You can obviously combine the two of these to hide page titles on a specific node type and on the front page of a Drupal 7 website using this code:

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

Pretty simple, but will hopefully provide a good reference for those looking to hide the page title on a Drupal 7 site.

Comments

How about display suite?

Confiurable, exportable (features), and keep display settings at the place where it makes sense: at the content type definition via a common interface by field_ui.

Exeptions are allowed of course ;-)

Hi,
I used your first option to hide title from all nodes and changed [is_front] to [node]. But unfortunally, Nothing changed.

Post new comment