Placed in: Home
Create a custom page title in Joomla 1.0.x

One of the most importart SEO factors there days is the ability to setup unique page titles whic reflect the content of each page. In Joomla 1.0.x this can be a little bit tricky, because it has a standard way of creating a page title.

There are a lot of tools (Artio, OpenSEF) that can create dynamic page titles, but they do more than you want. You just want control over the titles.

If you make these small amount of changes in the Joomla source code, the title will be created from the "Title Alias" that you fill in your back-end panel.

To get Joomla to use the title alias, use this code:

1. Open the following file:

components/com_content/content.php

 

2. Look for the following code:

// page title
 $mainframe->setPagetitle( $row->title );

 

3. Replace the code from 2. to this:

// If title alias < 20 characters, page title will be: Site name - title
 // else page title will be: title alias
 if (strlen($row->title_alias) < 20 )
 {
   $mainframe->setPagetitle( $row->title );
 }else{
   $mainframe->setPagetitlealias( $row->title_alias );
 }
 // END CODE SNIPPET 

 

4. Open the following file:

includes/joomla.php

 

5. Look for the following code:

function setPagetitle( $title=null ) {
 if (@$GLOBALS['mosConfig_pagetitles']) {
   $title = trim( htmlspecialchars( $title ) );
   $title = stripslashes($title);
   $this->_head['title'] = $title? $GLOBALS['mosConfig_sitename'] . '
 - '. $title : $GLOBALS['mosConfig_sitename'];
   }
 }

 

6. Add the following code after the code shown in 5.:

// setPagetitlealias - title of the content page to use tile_alias instead
 /**
 * @param string
 */
 function setPagetitlealias( $title_alias=null ) {
   if (@$GLOBALS['mosConfig_pagetitles']) {
     $title_alias = trim( htmlspecialchars( $title_alias ) );
     $title_alias = stripslashes($title_alias);
     $this->_head['title'] = $title_alias;
   }
 }
  // END CODE SNIPPET 

 

And there you have it. If the "Title alias" from any content now has more characters than 20, that will be the new page title. Enjoy.


Tags:  SEO joomla custom page title how to

Interested in this topic? You might enjoy another article I've written called

Did you like this article? Subscribe to my feed or email to keep updated on new articles.

Spread the word and submit to:
Digg!Reddit!Del.icio.us!Facebook!StumbleUpon!
Comments
Add NewSearchRSS
Rohit - Thanks a ton !!!   2008-01-05 15:29:12
Gravatar image man u rockkkkkkkkk its just so simple.. and i can live with putting my custom title tag in alis rather than having a dedicated field for it..
Ido Fishman - Custom Homepage Title   2008-05-26 10:00:22
Gravatar image Thanks for the help, I just have 1 more question - do you know how to change the homepage title?
Dinesh - Thanks for solution   2008-11-27 11:56:46
Gravatar image Once my friend asking me to change pages title and i confused how to do, but your solution is really cool to change title shortly and its also necessary from SEO point of view - Hosting24hour.com
Alison - Thank you thank you thank you!   2009-01-31 02:33:53
Gravatar image I think I love you... that is exactly what I needed. And so well explained. Thanks! Now I just have to figure out the same thin Ido was asking... I'll post it here if I figure it out.
Alison - How to Change title of Home Page   2009-01-31 02:59:53
Gravatar image Here's what I did to get the home page title as I wanted it.

1. I changed the code of setPageTitle() to leave out the URL and the dash. So now it is:

/**
* @param string
*/
function setPageTitle( $title=null ) {
if (@$GLOBALS['mosConfig_pagetitles']) {
$title = trim( htmlspecialchars( $title ) );
$title = stripslashes($title);
$this->_head['title'] = $title ? $GLOBALS['mosConfig_sitename'] . $title : $GLOBALS['mosConfig_sitename'];
}
}

2. Then I changed all references in content.php from setPageTitle/SetPageTitle to setPageTitleAlias so that setPageTitle doesn't get used for any page but the home page.

3. Then I changed back the line that controls the home page title, to not pass in a parameter. (The function is coded to handle this. It looks up the Site Name if there is no parameter passed in.)

function frontpage( $gid, &$access, $pop, $now, $limit, $limitstart ) {
....etc....
// Dynamic Page Title
$mainframe->SetPageTitle( );
....etc....
}

4. And finally I set the title that I wanted for the home page through the Admin back end.
Site -> Global Configuration -> Site
Site Name: the I want for my home page.

Since all the other pages do not use SetPageTitle() to set their title, I am free to use the Site Name: box to enter the for the home page.

Alison
Alex - NEED HELP   2009-03-15 18:02:26
Gravatar image hi can some one tell me whi after i maked a joomla acount i got demo???
i cant unpload or install nothing cuz is in demo 1.5 please HELP!!
Tanveer - Not working for me   2009-05-21 17:02:21
Gravatar image Hi,

I want to do the same as others, i dont want my dynamic pages to carry the title of the home page, title of my home page should not be visible when clicked any other link, I have tried changing the code according to this forum but didnt work for me, kindly help.

Tan
Toan - SEO   2009-06-18 06:58:25
Gravatar image Save the trouble of modifying the source file.
Download this plugin:

http://extensions.joomla.org/extensions/2641/details

works for joomla 1.0
Rainer - Perfect.   2009-07-07 21:21:02
Gravatar image Perfect. It works. <img src=illy:' />

Thank you for your nice tutorial .
Kenyan music - What about   2010-03-14 18:59:28
Gravatar image what about if I wanted to change the title tag for articles only?
Alessandro - don't work :(   2010-05-28 00:24:30
Gravatar image I'm following step by step this tutorial but it does not work.

I'using Joomla! 1.0.15. After I have done the change nothing happen to the title.
tercüme bürosu - tercume burosu   2010-07-17 16:00:21
Gravatar image thanks for codes
Paul Mason - Joomla 1.5 Page Title Customization   2010-12-24 00:18:22
Gravatar image I have a similar tutorial written for Joomla 1.5:

http://paulmason.name/blog/item/customizing-joomla-page-titles
Brisbane Plumber - Very helpful   2011-06-21 23:06:35
Gravatar image Thanks for the article, still useful for us using the legacy Joomla was searching for ages to find how to do this.
i - i   2011-08-05 11:40:17
Gravatar image An interesting approach to the topic, but I disagree.
Zeljko - Image link   2011-08-09 22:25:54
Gravatar image How To put on image link in joomla 1.0.xx put title tag?! Pleas Help Me!

Thanks
tercüme bürolar   2011-12-28 20:05:48
Gravatar image Thanks for sharing. It's the best ;)
tercüme bürolar   2011-12-28 20:06:21
Gravatar image Thanks for sharing. It's the best ;)
yeminli tercüme bürosu   2012-01-02 21:04:24
Gravatar image It works well. Very good...
Ankara Tercüme - Ankata Tercüme   2012-01-06 10:55:45
Gravatar image ankara tercüme very nice post thanks for sharing.
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev
Subscribe

Subscribe to Marcofolio