Login
Home
Eoin Bailey . com
Tech, Research, Code, Work, and Fun
  • Home
  • Eoin's CV
  • About Eoin
  • Ph.D.
  • Blog
  • Galleries
  • Training
  • Polls
  • Tags
  • Weblinks
  • Site map
  • Contact

A Random Image

6. A medium break...

Tag Cloud

algorithm antarctica apple banking browser code copyright cycle data centre devel Dijkstra drupal drupalcamp economics escapades facebook firefox galway Google iphone ipod livigno theme training weights
more tags

Hide a Node title in Drupal

Submitted by Eoin on Wed, 11/02/2009 - 17:34
in
  • Code-Work
  • 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.

  • Eoin's blog
  • Printer-friendly version
  • Send to friend

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This is exactly what I need...but

Submitted by Visitor (not verified) on Sat, 28/02/2009 - 00:14.

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?

  • reply

Where to edit the page.tpl.php file

Submitted by Eoin on Tue, 03/03/2009 - 10:28.

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"): ?>

<?php tells 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.

  • reply

no go

Submitted by Visitor (not verified) on Wed, 04/03/2009 - 02:07.

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.

  • reply

Tabs Still Printing in my checks

Submitted by Eoin on Wed, 04/03/2009 - 12:22.

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?

  • reply

Good work! Your post/article

Submitted by Zoran (not verified) on Mon, 23/03/2009 - 02:46.

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!

  • reply

What about if you want this

Submitted by Visitor (not verified) on Tue, 07/04/2009 - 07:47.

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?

  • reply

Write a new 'tpl' page for theming

Submitted by Eoin on Tue, 07/04/2009 - 11:57.

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!

  • reply

Node vs Page

Submitted by Visitor (not verified) on Thu, 24/12/2009 - 22:01.

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.

  • reply

page.tpl.php

Submitted by Visitor (not verified) on Thu, 24/12/2009 - 22:12.

http://www.ajaxhacking.com/156/changing_pagetpl_based_on_node_type

  • reply

what about a prefix?

Submitted by Carlo (not verified) on Tue, 28/04/2009 - 09:08.

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.

  • reply

Yeah, that would work

Submitted by Eoin on Tue, 28/04/2009 - 09:33.

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.

  • reply

The following page has

Submitted by Visitor (not verified) on Tue, 28/04/2009 - 15:53.

The following page has recently been added to D6 Documentation
http://drupal.org/node/426482

  • reply

thx

Submitted by gaming (not verified) on Tue, 26/05/2009 - 02:36.

That way you can theme every piece of a specific content type.

  • reply

Reply

Submitted by james090073 (not verified) on Fri, 05/06/2009 - 13:45.

Can you print the lines either side of the $title line, including the $tabs line, and the if statement?

  • reply

just looking around some

Submitted by newreil (not verified) on Sat, 13/06/2009 - 20:19.

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.

  • reply

Thanks for sharing this

Submitted by mojardon (not verified) on Mon, 15/06/2009 - 09:03.

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...

  • reply

Really good statements are

Submitted by vasts (not verified) on Thu, 18/06/2009 - 15:07.

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.

  • reply

Genius!

Submitted by Ariel (not verified) on Mon, 22/06/2009 - 22:10.

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

  • reply

This is really a good site.I

Submitted by pangle (not verified) on Tue, 23/06/2009 - 11:42.

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.

  • reply

The information you gave is

Submitted by acceler (not verified) on Wed, 24/06/2009 - 13:50.

The information you gave is good and I am in search of this type of material. Thanks for yoor post.

  • reply

SEO benefits

Submitted by Pro Source (not verified) on Sun, 14/03/2010 - 07:27.

Don't hide it, it has SEO benefits.

  • reply

Maybe

Submitted by Eoin on Tue, 06/04/2010 - 11:46.

It can have SEO benefits, but there having a website that appeals to users is also important. It's a balance.

  • reply

heheh good job man

Submitted by Visitor (not verified) on Tue, 13/07/2010 - 00:04.

heheh good job man

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options

Current Poll

Who is your favourite scientist?:

Freelance Work

A sample of websites I have developed:

  • Studio Richards
  • Medilex
  • Design21C
  • The Spine Clinic
  • Abrivia - Careers and Outplacement
  • Emilie Conway

Training

  • Spinning
  • Hodson Bay Hotel Training
  • Spinning Class - Not too Shabby!
  • Bike Time Trial
  • Spinning Class of Anti-Doom!

Some Links

  • James Bond Opening Scenes
  • Polls
  • Chess Module-Drupal
  • Ski Trip Jan 2009

Recent Comments

  • external controls via css classes instead of alternate text
  • What if there's more stuff
  • heheh good job man
  • Impressive confidence!
  • Honestly, you may think your
  • Maybe
  • SEO benefits
  • hey dat was nice
  • Time makes fools of us all.
  • I guess I'll have to update

Powered by

Powered by Drupal, an open source content management system

Recent blog posts

  • Intellectual Property, Copyright and Free
  • What Sites are using Drupal?
  • Hit The Road - version 2
  • Richard Feynman - On The Relevancy of Science
  • Lines of Communication are [too] Open?
  • Dublin Web Summit - June 2010
  • Reading Software Licence Agreements
  • PhD, Engineering, Tech - Updates
  • O2 Contracts
  • DrupalWest - Drupal Refresh
more
Copyright © 2010 Eoin Bailey . com.