How to Display Your Page Title in Your Template - Joomla! 1.5
Written by Cory |
June 05, 2008
|
(102)
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.5
If 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 Template
There 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 Title
The 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 Together
Using 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.
Trackback(0)
Comments (102)
written by Jason Boyette, June 06, 2008
written by Conlippert, June 09, 2008
Thank you Thank you!
written by MeSir, June 09, 2008
written by paul, June 11, 2008
written by paul, June 11, 2008
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.
written by paul, June 11, 2008
i read that article too - problem is i don't have "template manager" or "global config" under my "site" menu bar. weird.......
written by X_Burner, June 20, 2008
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
written by X_Burner, June 20, 2008
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
written by Ardi, June 30, 2008
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
written by Ardi, June 30, 2008
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"
written by Ardi, June 30, 2008
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
written by Ardi, June 30, 2008
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
written by Ardi, July 01, 2008
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
written by Ardi, July 01, 2008
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?
written by Ardi, July 03, 2008
* 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
written by Nilay, July 06, 2008
written by Tim Sutherland, July 07, 2008
written by Caleb Crosby, July 09, 2008
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!
written by Caleb Crosby, July 09, 2008
Again, thanks so much!!
written by Ardi, July 17, 2008
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.
written by Ardi, July 17, 2008
written by Ardi, July 21, 2008
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...
written by Jai, August 03, 2008
written by Raven, August 07, 2008
written by cchun39, August 17, 2008
sitename - category name - article title?
written by Paul, August 28, 2008
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
written by austin, September 07, 2008
I do not need my site name on each page once more it is redundant.
thanks,
-austin
written by Daniele, September 07, 2008
Thank you in advance
written by Daniele, September 07, 2008
The default page title in Joomla 1.5 is "Welcome to the Frontpage".
CHANGE CAN BE DONE FROM:
Joomla admin area > Menus > Main Menu > Home > Parameters - System > Page Title.
Type in the new page title you wish to use and save the change. Next time you open your website, the new page title will show up in your browser
written by Robert Stark, September 11, 2008
But I would like to modify it so it just shows which section I am in,
not the actual page title.
Eg "News" Not the title: "Taiwan has a new President"
Any ideas?
written by Tad Osborn, September 19, 2008
written by Tad Osborn, September 19, 2008
written by Leo Woods, September 25, 2008
This is just what I needed to know, now though I would like to display the category name and maybe the section name sometimes... How would I do these please??
Cheers
written by Dave, October 19, 2008
written by b, November 03, 2008
however I am having the same issues as X_burner...it's not working for me
neither in between or above the
written by b, November 03, 2008
I was saying that it's not working.
can it be because I'm using legacy mode?
unfortunately I can't turn it off to test it and make it work
thanks again in advance.
written by yness, December 10, 2008
Thanks again.
written by Gene, December 12, 2008
i want the site title to go first and then the individual page title on every page. "Sitename - Page Title". I tried reversing the order of the code but it broke the site.
Thanks
written by CrispyPapaya, January 02, 2009
is there a way to make it global???
written by Alex Tesler, January 05, 2009
written by Trav, January 06, 2009
written by Trav, January 06, 2009
cheers!
written by Michael Price, January 16, 2009
You write very good explanations.
I am completely new to this type of work and followed your instructions which partially worked.
I bought a template from Rocket Theme (not sure if this was a good idea?) – Versatility 4
My home page is called PIV.
In the ‘tab’ it knows says ‘Welcome to FrontPage – PIV. I guess this website, homeapage.
I have not put in the line
as it keeps on making the site crash.
Do you have any ideas on how to help me – or even hardcode Panama Investment Vacations into the tab.
Many thanks,
Mike
written by mi, January 19, 2009
I setup blank meta description in global settings and in frontpage now i have empty meta description.
I want to use this solution just to display meta description for frontpage, file index.php.
is it posible ?
marian
written by Mike C, January 19, 2009
written by Manjusha, January 21, 2009
Now, I was able to set the pagetitles for all the pages except the homepage. Since all other pages have been generated thru php, I added the code snippet as suggested by you in every php file. But what do I do about the homepage? Its the default Joomla 1.5 frontpage/homepage and its title is: "Home". I want to change this to my site's name. How do I fix this?
Thanks!
written by Manjusha, January 21, 2009
But changing the page title under Parameters (System) has caused the title to be displayed in the body of the home page. The title bar of the browser window still reads "Home"
written by Mike C, January 28, 2009
http://forum.joomla.org/viewto...5#p1009495
written by Daniel, February 07, 2009
How can I put my "Front Page Blog Layout" Page Title in "Home Page" title ? I have Menu Item Details Titke = Home, and for that Home page title become: "Sitename" - Home and i don't want this. I use this script:
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
$mydoc->setTitle($sitename.' - '.$mytitle);
Can you help me with this issue, I am looking for 2 weeks.
Thanks.
I need for my site: http://www.locatar.ro
written by Vernessa, February 11, 2009
written by ST Verschoof, February 18, 2009
written by Chris M, March 21, 2009
$mydoc->setTitle($mytitle.' - '.$sitename);
with:
if (trim($mytitle) == trim($sitename)) $mydoc->setTitle($sitename); else $mydoc->setTitle($mytitle.' - '.$sitename);
Just a thought for thoroughness sake.
written by yness2, March 26, 2009
Thanks!
written by moldy, April 08, 2009
written by Carl, April 09, 2009
Many thanks
Carl
www.barcelonayellow.com
written by Bill, April 19, 2009
How do you remove or change the "Welcome to the Frontpage" title?
From Joomla! Documentation
Jump to: navigation, search
The setting for the Page Title is located in the parameters of each Menu Item under "Parameters (System)".
For Example to change the Page Title for the Home page of the Sample web site, you would navigate to Menus / Main Menu, click on "Home" to open the Menu Item:[Edit] screen. Then click on "Parameters (System)" to show the System Parameters, and either change the "Page Title" parameter or set "Show Page Title" to "No".
written by دردشة, May 04, 2009
Many thanks
written by ratheesh, May 15, 2009
below is the code. i cannot find solution to this.the error is in the code i given the first line
$db =& JFactory::getDBO();
$query = 'SELECT * FROM jos_jportfolio_categories';
$db->setQuery( $query );
$rows = $db->loadObjectList();
echo $rows.'welcome';
written by usmarine, June 17, 2009
written by Szabi, July 19, 2009
Thank you,
Szabi Zs.
written by Ozzfest, September 16, 2009
written by Ty, October 06, 2009
im running joomla 1.5.14
I got no errors just the website title appear only..
written by Rhonda Bartlett, December 06, 2009
http://www.welcome2ky.com
Thanks so much!!!
written by Howard Just, December 24, 2009
How can I access the page keywords using JFactory and add the keywords to the end of the title tag?
Thanks again,
Howard
written by Howard Just, December 24, 2009
$mydoc =& JFactory::getDocument();
$mytitle = $mydoc->getTitle();
$mykeywords = $mydoc->getMetaData( 'keywords' );
$conf =& JFactory::getConfig();
$sitename = $conf->getValue('config.sitename');
$mydoc->setTitle($mytitle.' - '.$sitename.' - '.$mykeywords);
I understand that many search engines place more importance on the title than the keywords metatag, so placing the keywords in the title may help my SEO.
Thanks again,
Howard
written by mobile marketing, December 29, 2009
written by Oren, January 14, 2010
Can you show how to get the previous page title ( refered page)?
when i link a page to a form I'd like to give the user the information of what was the page he's requesting information about.
written by Chris Finnegan, February 04, 2010
I used this tip as part of a SEO technique. Add a H1 tag at the top of the page for keywords, and a shorter H2 tag for the article title. The Browser title matches the H1 page title (using the title manager plugin), and the URL includes the article title with the joomla core SEF. The effect can be seen here at www.clickwebdesign.com.au.
written by joomloo, February 07, 2010
I have system params set to "NO" for "show page title" and the "welcome to frontpage is STILL there" I've searched all over the internet - no luck! it just seems to be totally unresponsive. pls. help
Write comment
Join the HowToJoomla Community!
- Create a profile
- Connect with other members
of the community - All for FREE
Already a member? Login here.



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.