Want to hide a node or page title in Drupal?
Don't like having a title on top of your Drupal page? Some layouts simply look better without a title, or maybe you are building a page where a title just doesn't make sense. Whatever the reason, not being able to control the presence of a page title in Drupal can be annoying. For those that are new to Drupal, the terms node and page, for the sake of this article, can be considered one and the same. (A page is actually a type of node).
The blank space no longer
In older versions of Drupal, you were able to circumvent the need for a page title by simply entering a blank space (spacebar key). The space would register and the page would output without a title. You could not simply leave the node title blank, however, as this would throw an error. Unfortunately, entering a whitespace character no longer works. Newer versions of Drupal don't allow it anymore (you'll see an error telling you not to leave the node title blank).
A title helps with SEO
One of the most direct, obvious advantages of a page title is that it helps with SEO (Search Engine Optimization). If you're interested in learning more about SEO and search marketing, we invite you to visit our sister site, GuruofSearch.com. Typically, a well organized page that is ready to be indexed by search engines has a title tag and heading tags, with the page title contained in the top most heading tag, the h1 tag. However, if you leave your node title blank, or use the following method to leave out your node title entirely, you'll be missing this h1 tag. This is not necessarily a problem, as long as you manually add it back when you're writing your page content.
It's also worth noting that the method below retains your page title. The old method of simply inserting a blank space for the node title left you with an empty page title (the title that shows up in the heading bar of your browser window). The method below will retain your page title, as it allows you to enter a title for your page, yet not have it show up in h1 tags above your content. So, the top of your page will begin with what you type in the top of your editor window (the body), it will not contain anything, such as the page title, auto-generated by Drupal.
How to create a Drupal page with no title
One of the advantages of creating a node (page) with no title is that it lets you fully customize your page. Drupal won't be auto-generating any content that's not under your control. Use the following snippet in your page.tpl.php or page-front.tpl.php (for the front page) in place of the line that prints your title tag.
- Old (Bluemarine theme)
- <h1 class="title"><?php print $title ?></h1>
- Old (Garland theme)
- <?php if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
- <h1 class="title"><?php if ($title == "") print $title ?></h1>
What does the no node title code do?
So how does the code above work - what does it do exactly? You're basically asking the question: "If the page title is blank..." print the title within h1 tags. Since Drupal doesn't let you leave a blank title, the page title will never print out. Instead, you can fill in a descriptive title for your own reference, and the page title will still print in the title tags of your page, which is important for SEO. You can then add the page title, or a similar title of your choosing, back yourself within the body content, and, preferrably, within h1 tags.