Heya,
How do I hide the page title on my home page?

Comments

decibel.places’s picture

You can set its css to display: none;

Or you can find the code in the page.tpl.php template in your theme and delete or preferably comment out the code - or try looking in template.php and node.tpl.php

(always remember to back up the original files in case it doesn't work the way you planned!)

I think using css is preferable

I am working on a site with ALL the Drupal features hidden on the front end - for now we're using the back end - I think we will eventually want the community plumbing, so then it'll be easy to roll it out.

About half of the hiding is done with css, some had to be done in the php templates

The pages are made up of individual nodes assembled sort of like php includes

http://jcat.netsperience.org/

I also had to create a dedicated admin page for login and site management.

~are you netsperienced? http://netsperience.org

n6g9zty6’s picture

Oh you know I meant how to hide it only on the home page. As you probably know already display: none hides the title tag on every page, as would deleting the statement.

Thanks!

Spence
http://www.spencerhill.us

decibel.places’s picture

Use some js to test the location and hide/display accordingly...

<script language="javascript">
If (location=="your_home_page_url") getElementById("titleid").style.display="none";
</script>

replace titleid with id of title in your theme that you want to hide-

should work....

haven't tested it, but give it a try

~are you netsperienced? http://netsperience.org

nevets’s picture

Another approach, at the top of page.tpl.php add

<?php
if ( $is_front ) {
  unset($title);
}
?>

this will unset the title when view the front page (so it should not print).

decibel.places’s picture

Yeah, I think the php solution looks better

Is there a list of Drupal variables and tokens somewhere on this sprawling site, and tips on manipulating them?

~are you netsperienced? http://netsperience.org

nevets’s picture

For Drupal 5 see: http://drupal.org/phptemplate. Each of the links to a tpl.php file (ex: node.tpl.php) will list the variables available in that template.

n6g9zty6’s picture

Yeah PHP is the way to go in my opinion. But I inserted that statement and created a $title = 'home' but it didn't remove it... Can you show me an actual live excerpt?

Thanks!

Spence
http://www.spencerhill.us

nevets’s picture

What do you mean by "created a $title = 'home' ", you mean you created content with the title 'home'. Unless you make the content the default front page the title will show when viewing it.

n6g9zty6’s picture

I mean I made the following modification to the PHP you gave me and inserted it in the head of page.tpl.php:

<?php
$title = 'home'

if ( $is_front ) {
  unset($title);
}
?>

Thanks!

Spence
http://www.spencerhill.us

nevets’s picture

I added a semi-colon after $title = 'home' and placed the code segment right at the start of page.tpl.php and it worked fine.

n6g9zty6’s picture

Hm... still doesn't seem to be working for me... You mind taking a look at the site and the code for it?

http://www.spencerhill.us/green-dragon

You'll notice the linked title "Intro" at the top. That's what I'm trying to hide.

Thanks!

Spence
http://www.spencerhill.us

nevets’s picture

I would guess you are using the default front page (node) and promoting a single node to the front page. Try changing the front page to be just that node (ex: node/123, the 123 will be different for you). You can do this by visiting "Administer" > "Site configuration" > "Site information" and setting "Default front page".

n6g9zty6’s picture

You are the man. That was it.

Thanks!

Spence
http://www.spencerhill.us

sparkweb’s picture

This is a good solution in that it allows you to specify the title of the page in order to single it out by the actual text of the title. However, that's also it's drawback, because what if you change that title? You now have to make sure every page you promote to uses the name you specified in the tpl. But it's still a clever kluge.

vidyak’s picture

This worked for me , with box_grey theme.

Anonymous’s picture

I have discovered that hiding the node title has the side-effect of disabling RSS. Has anybody ran into this? Any ideas how to still hide the node title from my home page while keeping RSS enabled?

zenrei’s picture

I hadn't noticed that, either, but you're right!

RSS feed is gone now! How do we get that back?

zenrei’s picture

I added rss to the sidebar, but I'm not sure if the code is suppressing the front feed or not

Anonymous’s picture

Hello...this technique worked well for me..but i have another doubt. How to remove ' Posted Sun, 06/06/2010 - 17:32 by Anonymous ' just below the title?

dylanrao’s picture

I've tried your approach on page.tpl.php and page-front.tpl.php but I can't seem to get this to work. Do you know if there's anything different I need to do if working on a zen sub-theme?

mcfilms’s picture

You are in luck because Zen makes it super easy. There is a class called "front."

Classes on body include items like "logged-in", "not-logged-in", "front"...

So something like:

.front .title{
   display:none
}

is the quick solution to your problem.

A list of some of the Drupal sites I have designed and/or developed can be viewed at motioncity.com

Liam Ke’s picture

Useful

anthonym’s picture

I found another method useful on my site: create a specific node.tpl.php file for just the node(s) appearing on the front page. Details here: http://drupal.org/node/136647.

Anthony

aren cambre’s picture

I opened a feature request for this at #639966: Let us hide title on default front page.

sparkweb’s picture

I read some of the comments over there. Seriously? How could anyone not think this is a good idea, a most basic feature that should be there. Jeez.

Ok, yes, I come from Joomla too, but I've gotten pretty deep into Drupal too and it's earned quite a bit of respect. This is just such a basic feature to me I find myself really surprised there is no such built-in functionality in it.

jghyde’s picture

Instead of unset($title) which erases variables, why not copy your page.tpl.php to page-front.tpl.php.

At the top of the page-front.tpl.php, don't print the $title, eg at the top of page-front.tpl.php:

<head>
  <!-- <title><?php // print $head_title; ?></title> -->
  <?php print $head; ?>
  <?php print $styles; ?>
  <?php print $scripts; ?>
</head>

Joe
http://www.hydeinteractive.com/

Local News Platform Built on Drupal
http://sanangelolive.com/

decibel.places’s picture

@jghyde

<head>
  <?php print $head; ?>
  <?php print $styles; ?>
  <?php print $scripts; ?>
</head>

is a cleaner way...

nevets’s picture

Not very good SEO to leave the title tag out of head. Note this does not change the printing of $title on the page which is what the original question is about.

decibel.places’s picture

@nevets

you're right, this affects the DOM title but not the page title...

I have also found that when CSS alone cannot be specific enough, a bit of jQuery can work miracles eg #807014: exclude specific users and roles (eg admin) from public User List

juliavdw’s picture

Here is how I solved this issue, using page.tpl.php:

<?php if (!$is_front): ?>
<h1 class="title" id="page-title"><?php if (!empty($title)): print $title; endif; ?></h1>
<?php endif; ?>
lomo’s picture

I like the style you use with testing that the $title isn't empty before trying to print it. However in the unusual circumstances that you have a page with no title, do you really still want to print an empty <h1> tag-set into the page?

It might be an improvement to put the IF statement around the whole thing and/or combine the nested IF-statements, e.g.:

<?php if (!$is_front && !empty($title)): ?>
  <h1 class="title" id="page-title"><?php print $title; ?></h1>
<?php endif; ?>

See you at the Drupalcon!

decibel.places’s picture

An Omega Sub-theme has settings in "Toggle advanced elements" to hide the Page Title, Site Name, Site Slogan with CSS while leaving them accessible to screen readers.

see http://drupal.org/node/1298698

Yet another way :D

emeelio’s picture

This worked like a charm; thanks!

aniket_m’s picture

Hi
I am using omega theme.
Add these lines of code in your template.php

You can use print_r($vars['page']['content']); to see the variable which is printing this value
and accordingly you can manage it.

do use drupal_is_front_page() function otherwise it will hide page title for complete site.

/**
* Implements hook_process_page().
*/
function themename_process_page(&$vars){
if(drupal_is_front_page()) {
$vars['title']='';
unset($vars['page']['content']['content']['content']['system_main']['default_message']);
}
}

Thanks
aniket_m

hossamv’s picture

I was wondering isn't there an easier way for beginners like me. May be something so stupid like a toggle box. Or there's no place for such common-sense in the Drupal mind-set? I'd appreciate losing my time to build or to add something instead of losing time just to hide an ugly title that I didn't choose to place it there.

vm’s picture

No. There isn't a theme setting (toggle) in core to handle this.

tasetta’s picture

Juliadvw's solution working for me --

I replaced this

if ($title):
print $title;

endif;

in the page.tpl.php (main div section) with Julia's code and it worked perfectly for me. Hope this helps others.

(sorry, I don't know why the code breaks up into short sections when posted)

waqarit’s picture

Every page should contain a heading.

You should always maintain a structured hierarchy of headings within any web page. You should never have a blank heading or even hide it with display:none;. Hiding any content which isn’t viewable by your visitors but is by search engines is against Google’s guidelines as your intention is to only manipulate search engine results by including it. Restyle a H1 so it fits into your design is the best option.

If you still have to hide it then a better option would be to either create a template for that node, content type or page and simply not print the heading.
Or if you want to use CSS then use position:absolute so the heading doesn’t use any space where it is located in the page and text-indent:-9999px; so the text is moved off the screen and no longer visible but at least can be read by screen readers and search engines.

scottmorgan’s picture

In Drupal 7, copy page.tpl.php to page--front.tpl.php, which is a template overide for the front page only, and delete the title code.

nevets’s picture

Rather than copy page.tpl.php it would be easier to maintain a single copy and instead implement hook_preprocess_page() and hide the title element by setting '#access' to false

pownraj’s picture

Yes. You are right. We can always use preprocess hook

function THEMENAME_preprocess_page(&$variables) {
  // your condition; if (drupal_is_front())
  $variables['title']->access = false;  
}
hardik jayeshbhai hihoriya’s picture

I have Create new code Page Title hide in my home page..

template.php

function _themename_hide_page_title()
{
global $user;

$return_value = TRUE;
$current_path = current_path();
$patterns = theme_get_setting('hide_page_title');
if (empty($patterns)) {
return TRUE;
}
if (defined('LOGIN_REGISTER_ON_PAGE') && LOGIN_REGISTER_ON_PAGE && !$user->uid) {
$patterns .= "\n" . "user";
}
$path_alias = drupal_lookup_path('alias', $current_path);
if (drupal_match_path($current_path, $patterns) || drupal_match_path($path_alias, $patterns)) {
$return_value = FALSE;
}
return $return_value;
}