Hide a Node title in Drupal
I was working on a website, and I needed to a hide a title of a node. Any of you who have used Drupal know that you have to have a title for a page, so you can't just leave the entry blank, and because I wanted titles on other pages, I couldn't just erase the print $title value in the page.tpl.php file.
In the end, a very simple solution is what won out:
In the page.tpl.php file, add in an if statement, such as:
<?php if ($title!="Home"): ?>
<?php print $title ?>
<?php endif; ?>
Then, give the page in question a title of "Home", and voila, no more title on that page.














Comments
This is exactly what I need...but
This is exactly what I've been looking for...but I'm brand new to Drupal and coding in general. Can you please tell me, specifically where I should put this in my page.tpl.php file?
Where to edit the page.tpl.php file
This will work in most themes, but it is not a 100% guarantee, since some themes use sub-files for certain parts of the page. With that proviso, here is a more detailed method to making this change.
Before I go into the detail of the code, it is worth noting that you need to be sure that you are editing the 'page.tpl.php' file of the theme you are using. If you are using the default theme that comes with Drupal, you are using a theme called 'garland', and the page.tpl.php file can be located in
site_root/themes/garland/(also, you will have to ensure that when you update drupal you either don't overwrite this file, or you add the changes again).In Drupal 6.10, line 70 of the page.tpl.php file is as follows:
<?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>This is the line you want to edit. A quick change, that I have not fully tested (there might be an issue with tabs) is to change the line to the following:
<?php if ($title!="Home"): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>This will have the effect I described in the my post, (it's slightly different since different theme developers print the title value in different ways).
Some User Themes
Open the page.tpl.php file. In general, around a third of the way down the page you will find a line that will include the value
print $title(again, this is theme dependent, garland does it differently)This statement prints the value of the title of a node. If you want to remove the title of a node from every page just delete this statement entirely. If you want to only prevent the printing of a title on certain pages, on the line before the 'print $title' line, add in:
<?php if ($title!="Home"): ?><?phptells the server to interpret the following lines as PHP code.if ($title!="Home")tells the server that all lines until the 'endif' value will be executed if the condition is met. In this case the condition is actually a logical 'not' also, i.e. the conditional statement is logically reversed. This statement checks if the title value of the node is NOT 'Home', if it is not this value, then the next line is executed. In this case the next line is 'print $title', i.e. the title of the node is printed.What all this means is that if the value of the title of a node is 'Home' the title is not printed.
The line
<?php endif; ?>ends the conditional 'if' statement, and the remainder of the of the page.tpl.php file will work as before.NOTE 1: The value of the title and the check in the if statement can be anything you want. You could set it to check for 'No Title', and if a node has the title 'No Title' it will not print it.
Hope this helps.
no go
You gave some great instructions, but they aren't working for me on 6.10 bluemarine. Well, I got this one <?php if ($title!="Home"): print ''. $title .''; endif; ?> to work, but then my tabs were gone. This <?php if ($title!="Home"): ?> just didn't work at all.
Tabs Still Printing in my checks
I had a look at this on an install, it was working fine, tabs still printing.
Bluemarine theme prints the tabs via the next line in the page.tpl.php file, so provided that line is outside the if statement it should still be printing tabs.
Can you print the lines either side of the $title line, including the $tabs line, and the if statement?
Good work! Your post/article
Good work! Your post/article is an excellent example of why I keep comming back to read your excellent quality content that is forever updated. Thank you!
What about if you want this
What about if you want this to happen on more than just the Home page? Like let's say you have the name of 3 nodes you want to hide the title on, how would you modify the if statement?
Write a new 'tpl' page for theming
Sticking with this method, you can just set the name of each node as 'Home' and the if statement will be true for each of the pages.
When at Drupal Camp, there was a talk on advanced theming, which could come in handy. If you want to theme a specific content type you can create a new tpl file in the theme folder, named: "node-CONTENT-TYPE.tpl", e.g. node-poll.tpl. In this case whenever you visit a 'poll' content type the node-poll.tpl file will be used instead of the node.tpl file. That way you can theme every piece of a specific content type.
NOTE: I haven't made use of this technique yet!
Node vs Page
Well that works fine for Nodes. The node-whatever.tpl.php will only control the content of the node (more accurately $content). The title is also output to the page as part of the page.tpl.php so it will remain there whatever you do with the node template. You can create a override page.tpl.php file but it is a bit more involved.
page.tpl.php
http://www.ajaxhacking.com/156/changing_pagetpl_based_on_node_type
what about a prefix?
would it be hard to match a prefix (e.g. "hide - ") instead of a fixed word (e.g.: "Home")? Doing that, one could still track all the original page titles for admin purposes (e.g.: "hide - New York") rather than having hundreds of pages titled "Home". Thank you.
Yeah, that would work
Yep, you could add a prefix.
Though I think I would still recommend a new '
page.tpl.php' file for a specific content type. This is predicated on the fact that you will want to hide the title for a specific content type every time it is displayed.I'm writing up a new post that will explain how to do this more clearly. It should be up in a few days.
The following page has
The following page has recently been added to D6 Documentation
http://drupal.org/node/426482
thx
That way you can theme every piece of a specific content type.
Reply
Can you print the lines either side of the $title line, including the $tabs line, and the if statement?
just looking around some
just looking around some drupal sites, seems a pretty nice platform. I'm currently using Wordpress for a few of my sites but looking to change one of them over to drupal.
Thanks for sharing this
Thanks for sharing this information. I found it very informative as I have been researching a lot lately on practical matters such as you talk about...
Really good statements are
Really good statements are written.This statement checks if the title value of the node is NOT 'Home', if it is not this value, then the next line is executed. In this case the next line is 'print $title', i.e. the title of the node is printed.
Genius!
Just what I need! Works like a charm for me. Using Drupal 5.18 with framework theme. The key for me was this comment http://eoinbailey.com/blog/hide-node-title-drupal#comment-134
This is really a good site.I
This is really a good site.I wanted titles on other pages, I couldn't just erase the print $title value in the page.tpl.php file.
The information you gave is
The information you gave is good and I am in search of this type of material. Thanks for yoor post.
Post new comment