How-To Categories
Recent How-To's
News Feed E-mail
Login
| How to Display Your Page Title in Your Template - Joomla! 1.5 |
|
|
|
| Written by Cory | |
| Thursday, 05 June 2008 | |
|
In October 2006, I wrote a how-to for displaying your page title within your Joomla! 1.0 template. Since the release of Joomla! 1.5, I have gotten many requests for an article explaining how to do this in Joomla! 1.5. Here is how you do it... Page Titles in Joomla! 1.5If you've already worked with Joomla! 1.5, you know that page titles are handled differently than in version 1.0. In version 1.0, if you enabled dynamic page titles (see this article for an explanation), each page would have an html title of "Site Name - Page Title". For example, the HTML title of this page is "Cory Webb's How to Joomla! - How to Display Your Page Title in Your Template - Joomla! 1.5", where "Cory Webb's How To Joomla!" is the site name, and "How to Display Your Page Title in Your Template - Joomla! 1.5" is the page title. In Joomla! 1.5, dynamic page titles are used by default, and the site name is not displayed in the html title. For example, if this site were running in Joomla! 1.5, you could look up in the browser's window header and see that the html title just said "How to Display Your Page Title in Your Template - Joomla! 1.5". That makes things a bit easier in terms of getting access to the page title, but it causes another problem; your site name is not part of the html title. There is an SEF Patch that enables you to modify the HTML title, but I will show you a trick for doing this in your template. Think of this as 2 how-to's in 1. Accessing Your Page Title from Your TemplateThere are 2 objects in Joomla! 1.5 that are extremely powerful and extremely useful for doing some advanced tricks in your template. The first object is JFactory, which is basically the gateway for accessing just about anything in the Joomla! API, and the second is JDocument, which gives you access to your document's properties. Your document is usually defined as the HTML output from Joomla!, but it could also be a PDF, XML/RSS, or raw output/text. In this case, we are only concerned with the HTML output. To access your page title, simply add the following code to the top of your template "index.php" file: <?php $mydoc =& JFactory::getDocument(); $mytitle = $mydoc->getTitle(); ?> That's it. That's all there is to it. Pretty simple, huh? Now, to display your page title within your template, you simply add the following code anywhere in your template "index.php" file that you wish to display the page title: <?php echo $mytitle; ?> That's all there is to it. Pretty easy. Modifying Your HTML TitleThe next thing we want to do is modify your html title. We will be using the JDocument object that we just accessed. Using this code, you can set the html title of your page: $conf =& JFactory::getConfig(); $sitename = $conf->getValue('config.sitename'); $mydoc->setTitle($mytitle.' - '.$sitename); Notice that I used JFactory again to get a copy of the Joomla! configuration, which I then used to get the value of the site name (config.sitename). Then, I used "$mydoc" from the earlier step to set the html title. Note that this code sets the html title to "Page Title - Site Name". If you want to set it to "Site Name - Page Title", you need to change the setTitle parameter to "$sitename.' - '.$mytitle". In reality, you can set the html title to anything you want, but I personally think "Page Title - Site Name" makes the most sense. Putting it All TogetherUsing the following code, you are simultaneously getting dynamic access to your page title and setting the value of your html title: <?php $mydoc =& JFactory::getDocument(); $mytitle = $mydoc->getTitle(); $conf =& JFactory::getConfig(); $sitename = $conf->getValue('config.sitename'); $mydoc->setTitle($mytitle.' - '.$sitename); ?> Questions?As always, please feel free to post any questions or comments you might have.
Set as favorite
Bookmark
Email This
Hits: 4514 Trackback(0)
Comments (48)
![]()
Jason Boyette: ... http://www.jkboyette.com
Thanks for this tip - I was just searching around on the forums for something like this. I can't wait to try it out.
One reason I will probably change the title to "Site Name - Page Title" is so that my pages sort together when people look at their browser history. 1 report abuse
vote down
vote up
June 06, 2008
Votes: +0
Jason Boyette: ... http://www.jkboyette.com
Well, it works great. Just added it to my site, and I've got two other sites to update too. Thanks again.
3 report abuse
vote down
vote up
June 06, 2008
Votes: +1
Conlippert: ... http://www.twolipps.com
Thanks for this fix! I could hardly believe they omitted this in 1.5!
Thank you Thank you! 4 report abuse
vote down
vote up
June 09, 2008
Votes: +0
MeSir: ...
i was looking for hours on the internet , until i found this... thank you ... this is great ... tanks for sharing ... respect...
5 report abuse
vote down
vote up
June 09, 2008
Votes: +0
paul: ... http://www.filteredfocus.com
i had someone make my website, so i'm not sure what that index.php file is. i should have full access to everything, so it that something i can find?? please help, i really want to have page titles on my site!!
6 report abuse
vote down
vote up
June 11, 2008
Votes: +0
paul: ... http://www.filteredfocus.com
wow, your response time is incredible
i'm slow though - where would the templates folder be? under one of the menus along the top (ie: site, menu, content, etc.)? i know, i just think it's a nice subtle touch that's more professional looking. 8 report abuse
vote down
vote up
June 11, 2008
Votes: +0
paul: ... http://www.filteredfocus.com
thanks for the advice.
i read that article too - problem is i don't have "template manager" or "global config" under my "site" menu bar. weird....... 10 report abuse
vote down
vote up
June 11, 2008
Votes: +0
paul: ... http://www.filteredfocus.com
haha, bummer. ok, thank you!!
12 report abuse
vote down
vote up
June 11, 2008
Votes: +0
X_Burner: ... http://keinekistenschleppen.de/impressum/impressum.html
Hi Cory !
Thanks for your work and this tutorial. Ive integrated this: ...to my index.php but nothing happend !?! It seems the title wont override by the new title. How can I fix this? Greetz X_Burner 13 report abuse
vote down
vote up
June 20, 2008
Votes: +0
X_Burner: ... http://keinekistenschleppen.de/impressum/impressum.html
14 report abuse
vote down
vote up
June 20, 2008
Votes: +0
X_Burner: ... http://keinekistenschleppen.de/impressum/impressum.html
http://screencast.com/t/sytNq5qiPZz
Thanks for your quick response! X_Burner 16 report abuse
vote down
vote up
June 20, 2008
Votes: +0
X_Burner: ... http://keinekistenschleppen.de/impressum/impressum.html
Ive moved the php block up...but nothing changes
BEfore Ive tested this: And it works but so I got 2 titles Is there a other method to override the title ? Greetz X_Burner 18 report abuse
vote down
vote up
June 20, 2008
Votes: +0
frank: ... http://www.e-frank.com
Exactly what I was looking for. Thanks!
20 report abuse
vote down
vote up
June 20, 2008
Votes: +0
Zainal Ariffin: ... http://www.zainalariffin.com
This guide really works!! Thanks!! Good info..
![]() 21 report abuse
vote down
vote up
June 23, 2008
Votes: +1
Ardi: ... http://www.myfatherlandiran.com
Hi Cory.
thanks for your codes. it works somehow for me. i use it on title in index.php file but it changes my language (right to left) and structure of template. i mean every menus and banners are moves to right . the last combined code works and change the title but there is 2 problems 1. it changes the structure of website 2. title will change like this " welcome to front page - Freedom Fighter" god damn it i am tired of it. this welcome to front page is on my title and my front page. you can see it. please help me. what shall i do? by the way i add code in index file at the top of all lines but my front page editor move the code in the "body" i have some chat box in my web site you can leave comment there for me or answer it here . it doesn't matter att all. thank you too much 22 report abuse
vote down
vote up
June 30, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
Cory thanks .. it was great help.......
at least i could find that damn name "welcome to front page" and change it. so now title changed and i demand you tell me please : does it has effect in Google and the title also will change in google? if it is, then shall i use the codes or no? because my problem was in google that it showed my web title "welcome to front page" 24 report abuse
vote down
vote up
June 30, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
so it is still changes my web structure. i tried all codes separate and has same effects. so i will wait for few days and if title wouldn't change then we will see what i have to do. just tell me which code is better for me to use?
do you have any codes that i use in my web site to show some media player for music? some good one with nice skins? thank you too much that help me .. you are very nice... you made me happy and stop my headache ![]() 26 report abuse
vote down
vote up
June 30, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
Holy god...
lol... i forgot something else ..please forgive me for my many questions. do you know how shall i change the small logo of joomla on my address bar? some people has some personal logo or small photos on left side of web side address on address bar. this is my last question. thanks for media ![]() 28 report abuse
vote down
vote up
June 30, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
Hello again Cory
i made my favicon.ico and replace it with the old one . also i added a new code in my index file but still it doesn't work. this is my code and tell me where shall i add it? also tell me if it is incorrect code. thanks 30 report abuse
vote down
vote up
July 01, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
well i am trying to clear fire fox cache and i can not find it...!!! so it is still same for me. anyway.
about that website that you told me. i checked it and download something but when i wanna install it on website it shows the message " * Warning! - Failed to change file permissions * JFolder::create: Path not in open_basedir paths * Unable to create destination what is it ???? this is the first time i see this message. i wanted to add some comment system ( to leave comment on articles in joomla) but i have no idea what is good. do you know some? 32 report abuse
vote down
vote up
July 01, 2008
Votes: +0
Amy Andrews: ... http://amyandrews.name
Thanks so much for this! It worked great!
33 report abuse
vote down
vote up
July 01, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
hello everybody. cory was busy and didn't answer me. does anybody know why when i wanna install some programs on website it shows the message "
* Warning! - Failed to change file permissions * JFolder::create: Path not in open_basedir paths * Unable to create destination what is it ???? this is the first time i see this message. and i wanted to add some comment system ( to leave comment on articles in joomla) but i have no idea what is good. do you know some? please someone help me ![]() 34 report abuse
vote down
vote up
July 03, 2008
Votes: +0
Nilay: ...
Thanks for the fix. Is there a way to remove 'Home' from the title. After the fix it says 'Home - site title'. Thanks.
36 report abuse
vote down
vote up
July 06, 2008
Votes: +0
Tim Sutherland: ... http://www.soulsensations.com.au
Thanks for this Cory. I'm new to Joomla and was getting annoyed by having to repeat the site name in the title field for each article. It makes sense now that I've done it and with some basic understanding of PHP and the Joomla API I guess the possibilities are endless when it comes to adding dynamic content to pages via the template.
37 report abuse
vote down
vote up
July 06, 2008
Votes: +0
Caleb Crosby: ...
This is a great tutorial! Thank you so much!
I have a the Title Manager plugin installed so I am able to concatenate my site name into the page title. Naturally, using the document title in the template will now pull in my entire site name too. Is there a way to pull in just the current article title? Thanks again! Your site is a tremendous resource! 38 report abuse
vote down
vote up
July 09, 2008
Votes: +0
Caleb Crosby: ...
In thinking about it more, I'm wondering if you can show us how to access the menu titles too? This would add a ton of flexibility in how people use this technique to display a title in their template.
Again, thanks so much!! 39 report abuse
vote down
vote up
July 09, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
hi Cory
my problem didn't solve and still i have this error when install anything as follow : * Warning! - Failed to change file permissions * JFolder::create: Path not in open_basedir paths * Unable to create destination please tell me what i have to do... i am exhausted of joomla..also my admin server was crazy and installed my safe mode = off ...!!! how can i turn it on. i beg you find some solution for it. 40 report abuse
vote down
vote up
July 17, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
all my permissions are writeable and ok. but i do not know why it happen to me
41 report abuse
vote down
vote up
July 17, 2008
Votes: +0
Ardi: ... http://www.myfatherlandiran.com
Hi cory
another thing is that how shall i change my FTP setting? because i put my web site url in FTP host and it doesn't work (has error) and when i add the name of my server FTP address ( D:WWWPESmyfatherlandiranc.....) it has eroor when i enabale FTP as follow: JFTP::connect: Could not connect to host "D:WWWPESmyfatherlandirancwww m" on port 21 do you know how to do it? may be if i change this then i can install my components or plugins... 43 report abuse
vote down
vote up
July 21, 2008
Votes: +0
Jai: ... http://www.studentmagazine.co.cc/
That was incredibly easy. I thought I'd have to go through a long winded process to solve the issue, until I found this. Thank you so much for your help!
44 report abuse
vote down
vote up
August 03, 2008
Votes: +0
Raven: ... http://www.aaanativearts.com
Thanks for the call title tip. However, from a SEO standpoint, it is better NOT to call your site title as part of the page title. Your page will rank much higher without it, sometimes 10-20 slots higher!
45 report abuse
vote down
vote up
August 07, 2008
Votes: +0
cchun39: ...
Great tip, thanks. Had a question, is it possible for it to show up:
sitename - category name - article title? 46 report abuse
vote down
vote up
August 17, 2008
Votes: +0
Volker: ... http://www.riddla.de
$this->getTitle() should do the trick also...
47 report abuse
vote down
vote up
August 19, 2008
Votes: +0
Paul: ...
I found this extremely useful! THANKS!
I’m using this for meta tags and so far I’ve been able to use this technique for the following: $mydoc =& JFactory::getDocument(); $description = $mydoc->getDescription(); $generator = $mydoc->getGenerator(); $keywords = $mydoc->getMetaData( 'keywords' ); $author = $mydoc->getMetaData( 'author' ); $mytitle = $mydoc->getTitle(); $conf =& JFactory::getConfig(); $sitename = $conf->getValue('config.sitename'); But I can’t get the “Modified Date” to work. I’ve tried this: $mdate = $mydoc->getModifiedDate(); ( But, it simply shows the current date and time. I’d also like to be able to use the “Created Date” but have found no documentation on getting this at all. Thanks Paul 48 report abuse
vote down
vote up
August 27, 2008
Votes: +0 Write comment
|
| Next > |
|---|










