0

I found following code on this website http://codekarate.com/content/hiding-page-titles-specific-node-types-drupal-6 to hide the page titles of some content types.

Can some one help me rewrite this for drupal 7 ??

function THEMENAME_preprocess_page(&$vars) {
  $vars['original_title'] = $vars['title'];
  if (!empty($vars['node']) && in_array($vars['node']->type, array('NODETYPE'))) {
    $vars['title'] = '';
  }
}
1
  • Did you alteady try it? Looks like ok.
    – kala4ek
    Jun 6, 2015 at 10:21

3 Answers 3

1

Just wanted to let you know that there is a module that does this Exclude Node Tittle

enter image description here

4
  • I tried that but that does not provide any option to remove title for selected content types. Please advise if that allows ? Jun 6, 2015 at 16:44
  • @Fahad it's right in the first paragraph of the description: "Also provides the option to hide all titles of a certain Content type."
    – Geoff
    Jun 6, 2015 at 17:43
  • @Fahad it does allow you to, see picture.
    – No Sssweat
    Jun 6, 2015 at 18:21
  • @Fahad For example: In the above picture, if you want to have the title show up in Basic Page, you have to uncheck mark the exclude from full view and teaser, under Basic Page.
    – No Sssweat
    Jun 6, 2015 at 18:57
1

The code should work just fine in Drupal 7. But note that it only works on node pages (where the URL is node/[nid]) and does not work on lists of teases make with Views or the default Drupal frontpage.

I made a small modification to the code below using 'page' and 'article' as example content types instead of NODETYPE.

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

If you don't want to use exclude_node_title you can do this:

on your theme edit the template.php and add/modify this hook:

function YORTHEME_preprocess_page(&$vars) {
 $vars['show_title'] = TRUE;
  if (isset($vars['node'])) {
    if ($vars['node']->type == 'YOURTYPE') {
      $vars['show_title'] = FALSE;
    }
  }
}

and on your page.tpl look for the part where the title is shown and use the show_title variable in this way:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.