Printing pagename and sitename in page.tpl.php

technology-now - July 3, 2009 - 10:03

I'm using Garland and I wanted to change the header title-tag from PAGENAME | SITENAME to just PAGENAME.

I changed part of the page.tpl.php

FROM:

<?php
print $head_title
?>

TO:

<?php
print $title
?>

THIS WORKED FINE,

Every page except the front page now has the title-tag PAGENAME as I wanted

BUT

My front page shows no title-tag at all.

I want to keep the amended code, and keep the PAGENAME as the title-tag for all other pages,
but I also want to have the SITENAME for the title-tag on my front page.
How do I change my new code to achieve this?

Can anyone help with the correct code?

you can use page_title module

pinky.cms - July 3, 2009 - 10:15

Hello,

you can use page_title module. it provide settings for front page and other pages. you can have different page title instead of node title for the nodes.

Regards,
Pinky

Hi, The $head_title variable

anotherdave - July 3, 2009 - 10:25

Hi,

The $head_title variable prints the page name, followed by a pipe (|), followed by the site name. The $site_name variable prints out the site name on it's own in the same way that $title variable prints the node title on its own.

If you're using Garland, you should have a file page-front.tpl.php - what is in between the <title> tags here? You should be able to put <?php print $head_title; ?> or <?php print $site_name;?> here, which will hopefully fix that problem.

Just to point out that having both the node title and site title is generally seen as best practice for SEO and usability, but it's up to you.

All the best
Dave

"Set a man a flame, keep him warm for a day. Set a man aflame, keep him warm for the rest of his life."

As a PS, when starting I

anotherdave - July 3, 2009 - 10:30

As a PS, when starting I found this page invaluable:

Also check out the ones for node.tpl.php, comment.tpl.php, etc.

All the best
Dave

"Set a man a flame, keep him warm for a day. Set a man aflame, keep him warm for the rest of his life."

Thanks. I've taken your SEO

technology-now - July 3, 2009 - 11:03

Thanks.

I've taken your SEO advice and changed the code back to what it was originally.

I'm also taking your recommendation and will do a bit of bedtime reading.

Thanks everyone.

Cool, glad to be of

anotherdave - July 3, 2009 - 13:16

Cool, glad to be of help.

Dave

"Set a man a flame, keep him warm for a day. Set a man aflame, keep him warm for the rest of his life."

if you want to do this by

pinky.cms - July 3, 2009 - 10:48

if you want to do this by code, you can try this

<?php
if (drupal_is_front_page()) {
  print
$site_name;
}
else {
  print
$title;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.