How to hide a node title?

So a client wants a site with a custom front page. After struggling with Panels and a number of options, I decided the easiest way to go about this particular request was a regular node, with blocks turned off.

One problem: the node's title was also appearing at top, messing up the graphic look needed. I wanted no title to appear, but Drupal doesn't allow a node without a title, and there's no built-in way to have a node appear with its title invisible.

Question answer

Searching the drupal.org forums turns up a lot of possible solutions, most complex. But among the many solutions on this page http://drupal.org/node/2420, one by donnoit looked simple enough even for me:

Edit page.tpl.php in your theme dir and change the line that checks title != "" to title != "x". Then simply give x as the title to your page and it shouldn't show up.

Okay. I opened page.tpl.php for the theme in question, found this line

<?php if ($title!): ?><h1 class="title">
<?php print $title; ?></h1><?php endif; ?>

and changed it to this:

<?php if ($title!="welcome"): ?><h1 class="title">
<?php print $title; ?></h1><?php endif; ?>

where "welcome" (without quotes) is the title of my front-page node.

It works! The node content appears, but Drupal doesn't print out its title. Thanks, donnoit!

Average: 4.3 (7 votes)

Trackback URL for this post:

http://www.drupalace.com/trackback/23

Re: Trick Bin: Hiding a Node Title

I like this solution for the "quick fix"...

However, it seems like there should be a much easier (Modular) solution to this. This is an option that I use VERY regularly when putting sites together... there may be tons of splash pages for sections of a site that are heavy on graphics, and nothing like the content of the rest of the site.

I'm new to drupal myself, but couldn't it be solved using page-front.tpl.php for your homepage, and removing the title from that one?

I'm still trying to figure the best way to display custom content using views, cck, the nodeteaser on your recommendation, and my custom regions that I have in my homepage layout.

seriously though, this should be a default option...a lil checkbox for "display title" checked by default... or a pretty simple module could do the trick. " I say that, but my first custom module has yet to be finished... so easy sounds easy, but maybe not quite...

Re: Trick Bin: Hiding a Node Title

Hello! I believe you are completely right: a separate tpl.php page for the homepage is one way to go about it, and is a good solution for many custom page needs. I myself haven't implemented that, but I've seen the method suggested in answer to many drupal.org forum questions. All it takes is a little willingness to learn to parse PHP; for tpl.php files, I find that isn't too hard. (But I haven't tried any really fancy tricks yet, either.)

I also agree thoroughly about having show/hide title (or other fields) as a per-node checkbox option; that would be wonderful! To have titles, teasers, author info, etc. all implemented consistently with a simple option for show/hide, as a part of Drupal core, would add great flexibility to page display.