How do I customize the <TITLE> on all pages?
liza - January 14, 2006 - 03:30
I am going to try this one more time. We have tried to customize TITLE in order for it to show
SITE NAME | Title of the post
in the PHPTemplate
<title><?php print $head_title ?></title>and in THEME.inc
$output .= ' <title>'. (drupal_get_title() ? strip_tags(drupal_get_title()) : variable_get('site_name', 'drupal')) .'</title>';Nothing works.

can you give us a bit more
can you give us a bit more info?
what theme are you using? If it is a custom theme, then what template engine are you using?
you said "I am going to try this one more time." does this mean that you have tried this before, or that you have tried to get help with this before?
changing theme.inc probably won't help, since your current theme is probably overriding it, anyway.
This is non-trivial
I did this with my site when I converted to drupal about 6 months ago. You need to store the title you want for each page in the DB or use that formula you indicate. There is a module called nodewords which allows you to set keywords and meta-description for each page. I added title, but needed to hack various core scripts to get it working the way I wanted. Note that nodewords for 4.7 (or CVS) is significantly improved from 4.6. You are welcome to my code, it is not pretty, but it does what I want and it has paid off for Google, Yahoo and MSN.
www.scryptik.com - Javascript editor with syntax error checking
Fuddieish?
Hi,
You state things that are not true. The fact that you did not manage to achieve this easily, does not mean that it *is* non-trivial. What you want it *very* easy, but requires some knowledge about the various theme hooks. I suggest you search for the hook_head and for how to print additional variales in your phptemplate. It is really easy.
---
Bèr Kessels
Professional www.webschuur.com
Personal bler.webschuur.com
theme.inc? phptemplate? what the hack are you hacking?
You should never -ever- touch those core files for such trivial things.
quick example how to achieve this in bluemarine:
<title><?php print $site_name ?> presents: <?php print $title ?></title>renders:
Laura S presents: My First Post
And if this helps you, I would be very, very pleased if you could show your appreciation by making this into a theme snippet in our handbooks.
---
Bèr Kessels
Professional www.webschuur.com
Personal bler.webschuur.com
book page
Just started a handbook page and snippet for theming the blogs
Dub
this is not a theme issue
i've made the appropriate changes in the theme. this is an issue of how the TITLE information is output to the search engines; and unbelieveably, this looks like it's hard-coded in Drupal.
liza.
You are doing it again:
I gave you an answer. Spent my time to explain in code how your problem could be fixed.
Next you comment that it seems not to work:
* without providing *what* you want to get to work
* without telling what I misunderstood, or did wrong
* But with telling that it is "unbelieveably, this looks like it's hard-coded in Drupal."
1: *what is hardcoded*? The title generation is handled by the theme. full stop. Nothing hardcoded!
2: what are you trying?
If you post harsh voiced comments, you can expect them back. So please be more friendly and polite if you want people to help you fix this problem.
It is not *we* vs *you*. we can also solve your problem together.
---
Bèr Kessels
Professional www.webschuur.com
Personal bler.webschuur.com
Ber, this is not a trivial matter
My follow-up is here :
http://lizasabater.com/blog/2006_jan_sat/liza/the_politics_of_code
Why is this harder than it ought to be
I am the publisher of the blog.
I am the marketer of the blog.
I own the blog.
Who ought to make the decision of where the name of the blog and the title appears in Google and other search engines?
Me.
Not Ber Kessel.
Not Dries Buytaert.
Not Kieran Lal.
This decision should squarely fall on me and only me.
Why in the world do you want to hard code this.
http://lizasabater.com/image/liza/drupal_code_madness
Anybody with basic knowledge of user interfaces will know that the left side is where you start looking at things on a browser --at least in most of the world that reads from left-to-right. This is the most important 'hot zone' of the browser.
I am in the business of bootstrapping the promotion of my brands and do so by all means necessary. That is why, as a publisher, I want the name of my blog to appear on the left side of the screen.
Why is this decision being made for me by Drupal?
try this..
Hi Liza..
Try this
in your page.tpl.php, at the very top where Drupal determines the page header change the bit that says
<title><?php print $head_title;?></title>to this:
<title><?php if (arg(0) == 'blog')
{print // insert your customised page title tag here }
else {print $head_title;}
?>
</title>
See Bers post above for a tip on how to insert the customised header tag.
It could be something like this:
Liza's blog: How to use the search on drupal.org
as opposed to the default. Which is Node title : site name
if you want it to happen everywhere...just follow what Ber said above. the snippet I posted just changes the format on the "blog" nodes.
hope that helps
Dub
Thanks for the heads up but
It still does not solve how Google is indexing the posts.
Sure it does
Google indexes the very same page you see -- but it takes them time to do that. Their indexing software can only check your site so often with the millions (billions?) of pages it has to go through.
Note: If you have the google site map module you might want to make sure it's submitting page titles correctly.
it is not liza telling me what to do
Liza. Really. you attacked me personally. If you cannot live with the way we work, then please move on, and stop ruining peoples mood by insulting them!
There are other CMSes out there. I suggest you look for a comercial one, so that you can pay people to do things you want them to do.
Bèr
---
Bèr Kessels
Professional www.webschuur.com
Personal bler.webschuur.com
Clarification and one solution (albeit an aesthetic one)
There are two issues to this problem :
(1) How do you change what appear on the browser in the TITLE area. This is a cosmetic change.
(2) How do you change TITLEs so they'll appear a specific way on search engine results. This is the focus of my frustration.
For those of you wondering about the cosmetic change, the place to change this is in the PHPTEMPLATE.ENGINE file, which is found in /THEMES/ENGINES/PHPTEMPLATE.
Just find 'head_title' in the file and change this :
'head_title' => (drupal_get_title() ? strip_tags(drupal_get_title()) .' | '. variable_get('site_name', 'drupal') : variable_get('site_name', 'drupal') .' | '. variable_get('site_slogan', '')),To this :
'head_title' => variable_get('site_name', 'drupal') .' | '. (drupal_get_title() ? strip_tags(drupal_get_title()) : variable_get('site_name', 'drupal') .' | '. variable_get('site_slogan', '')),When I changed this, I thought it would have an impact on how GOOGLE would index the titles of my site's entries. It hasn't. It's an aesthetic change that I really do not care for.
What I want is for GOOGLE to index all my site's entries with the name of the site first, the title of the entry second.
Is that too much to ask?
This is something I had total control with other blogging software. The decision was mine, not the software developers' decision.
slightly confused liza...can you help?
Hi Liza,
According to a few websites discussing search engine optimisation, the general consensus appears to be as follows:
From 456bereastreet.com
Besides, I always thought google picked up the tag in HTML and if you change anything, you simply had to wait until google refreshed your indexed pages.
For example, let's say you wanted to reverse the order of your page header titles from "page title: Site name" to "Site name : page title"..but google had already indexed the default way. Wouldn't it take a period of time before google.com re-indexes your site?
Or do you have something that Controls what gets indexed in the robots.txt file?
the general standard appears to be what the guys at 456bereastreet.com specified. it would be good to know if you have an inside line on why the other way around is better.
Dub
It's a branding thing
I want to differentiate my content from the rest. Having the name of the blog before the title is a good way of distinguishing content on the page when you have list of titles that look the same.
Many people have their theories about how SEO works.
What the engines do is one thing, but how people search for information and find it on a browser is very different. I am going for the eye-tracking factor here :
http://www.eyetools.com/inpage/research_google_eyetracking_heatmap.htm
http://www.webmarketingworkshop.co.uk/newsletter-april05.htm
http://ww1.prweb.com/prfiles/2005/02/28/213516/cropped.jpg
It does not matter whether I am right or wrong. The point is, it is not up to Drupal to decide where a blog's name appears on a Google search. That's a decision that ought to be left to the publisher.
sorry Liza...am Still confused..
hi Liza,
Thanks for the heads up on that, but, I'm still slightly confused. Sorry.
Are you saying that Drupal doesn't allow you to change how the site page headers are constructed?
Dub
it's an attention to detail thing
Hi Liza,
I think it's unfair of you to attack Drupal in such a way. describing drupal is "fascist" as you have done on your Drupal driven website is very narrow-minded. It's an attention to detail thing, not a branding thing.
if you think that it would improve Drupal, it would be very useful if you could
- submit a feature request to include an option on the Drupal site settings page for changing how page titles are displayed.
- Submit a handbook page here http://drupal.org/node/20639 which is a section of the handbook about "Helping search engines".
thankfully other Drupal users understand that Drupal is an open-source community developed tool and instead of slagging it off, they help to improve it either by submitting patches to bugs, handbook pages explaining how to do things or submitting feature requests.
philk
handbook page for this
Hi Phil,
Fow what it's worth...I have setup a new book page explaining how to change the way Drupal constructs the page header titles and a quick analysis of how some famous sites do it.
A simple search on this forum would have popped up an answer to the original query...so hopefully, the handbook page will help others in the future.
Worth noting that some of the bigger web sites like wikipedia.org, wordpress.org, drupal.org, nytimes.com, theregister.com, theonion.com among others use the same format as the Drupal default i.e. NODE TITLE | SITE NAME.
Hope that helps others.
Dub
Ummmmmmm, trivial
Drupal does hard code the generation of <title> based on site name and posting title. This is quite good, but IMHO can be better. I am 100% with your post above about who sets the title. The title tag is the single most important on-page SE optimisation factor, and requires hand crafting.
I would hesitate before putting your site name at the beggining of the title tag, you may be better off putting it at the end or leaving it out.
My experience is not with blog entries but for pages. I accept that one should NEVER hack the core, but I have got good SERPs and that is more important to me. I would like nodewords to include <title> and it to be put in core, but this could be inflamatory!
www.scryptik.com - Javascript editor with syntax error checking
quick one..
interesting discussion
3 quick questions..
Do you use Drupals default tag, i.e. page title ¦ sitename or the reverse?
Do you use node search engine tags module?
do you use a robots.txt with Drupal?
Dub
Yes and No!
No, I don't use default title tag.
Yes, but I have modified it to include title plus mods in core.
Yes, there is a robots.txt, vanilla, I would have to check what it contains.
www.scryptik.com - Javascript editor with syntax error checking
Thanks.
This :
is the key to this whole discussion.
Cache?
I can only guess that google is caching your page titles in some way. If you have already changed the output in the theme, could you check how new pages are indexed? I can see no way for google (or any other crawler) to use a title which doesn't appear on the page.