Hide the Node Title on a Page (5.x)
Last modified: August 27, 2009 - 00:23
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 breadcrumbs if desired.
<?php
// Titles are ignored by content type when they are not desired in the design.
$vars['breadcrumb_title'] = $vars['title'];
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (in_array($node->type, array('page', 'story'))) {
$vars['title'] = '';
}
}
?>This is where the code belongs in the _phptemplate_variables() function:
<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'page':
// Titles are ignored by content type when they are not desired in the design.
$vars['breadcrumb_title'] = $vars['title'];
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if (in_array($node->type, array('page', 'story'))) {
$vars['title'] = '';
}
}
break;
}
return $vars;
}
?>Hide Node Title on Front Page
Here is an example of a way to accomplish this only on the front page. Wrap the H1 in your page.tpl.php with the 1st and 3rd line of this code example. The second line is an example of what may be publishing your title in page.tpl.php.
<?php if ($title && !$is_front): ?>
<h1 class="title"><?php print $title; ?></h1>
<?php endif; ?>
Hidding by user
I have implemented a tip to allow the user type "__The title of node__" (double underscore) to hide the node title:
<?php
/**
* Override or insert PHPTemplate variables into the templates.
*/
function _phptemplate_variables($hook, $vars) {
switch ($hook) {
case 'page':
// add from here
if (preg_match('/^__(.*)__$/', $vars['title'], $regs)) {
$vars['title'] = '';
$vars['head_title'] = $regs[1];
}
// add to here
break;
}
return $vars;
}
?>
Note title appears on HTML head-title node...
Does it works on Drupal 6 as
Does it works on Drupal 6 as well.
The Hide Node Title on Front
The Hide Node Title on Front Page part works with the Drupal 6 page.tpl.php theme file, I used it to hide the feed icon from my front page:
<?php if ($title && !$is_front): ?><?php print $feed_icons; ?>
<?php endif; ?>
http://jabbtech.com
does not work...
in 6.x and latest acquia_marina theme, cant even find the function to put the code in.