Custom Title Tag Hack for every page

Your code modifications and patches you want to share with others.
User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Custom Title Tag Hack for every page

Postby barnett » Wed Feb 08, 2006 7:51 pm

Many have talked about needing the ability to create custom title tags for every page.

http://forum.joomla.org/index.php/topic,11357.0.html
http://forum.joomla.org/index.php/topic,18041.0.html

This hack will accomplish allowing you to set custom Title Tags for every menu item and content item in the parameter fields.  This will help with SEO of your Joomla site unitl these issues are hopefully implemented in Joomla 1.1.

Here are the steps:
Please backup your files first

1. Insert Custom Title Tag Parameters

add the following line of code as a childNode of the node

Code: Select all

<param name="title_cust" type="text" size="20" default="" label="Custom Title Tag" description="A custom Title tag to be applied to the page, this allows individual page titling" />

in the following .xml files:


administrator/components/com_menus/component_item_link/component_item_link.xml
and every subfolder under the com_menus/ directory that contains a .xml file. (ex. content_section/content_section.xml)

administrator/components/com_banners/banners.xml
and every subfolder under the administrator/components/ directory that contains a .xml installer file. (ex. com_frontpage/frontpage.xml)
Note: when you install a new component you will have to add the line of code to the component's .xml installer file


2. Edit content.php File

open file: components/com_content/content.php

look under the function showItem and replace the following code around line 1341:

Code: Select all

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


with this:

Code: Select all

// page title
$mainframe->setPageTitle( $row->title, $params );



3. Edit joomla.php File

open file: includes/joomla.php (for Mambo: includes/mambo.php)

look for function setPageTitle under the class mosMainFrame around line 468 and replace:  (Mambo line: 128)

Code: Select all

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


with this:

Code: Select all

   function setPageTitle( $title=null, $params=null ) {
      if (@$GLOBALS['mosConfig_pagetitles']) {
         if ($params) {
            $custom_title = $params->def( 'title_cust', '' );
         } else {
            global $database, $mainframe, $Itemid;
            $params = new stdClass();
            if ( $Itemid ) {
               $menu = new mosMenu( $database );
               $menu->load( $Itemid );
               $params = new mosParameters( $menu->params );
            } else {
               $menu = "";
               $params = new mosParameters( '' );   
            }
            $custom_title = $params->def( 'title_cust', '' );
         }
         $title = $custom_title ? $custom_title : $GLOBALS['mosConfig_sitename'] . ' - '. $title;
         $title = trim( htmlspecialchars( $title ) );
         $this->_head['title'] = $title ? $title : $GLOBALS['mosConfig_sitename'];
      }
   }



4. Edit the root index.php File  *new addition

open file: index.php  (not your template one, but the actual one in your root folder of your Joomla install)

after line 100 where you see this:

Code: Select all

// mainframe is an API workhorse, lots of 'core' interaction routines
$mainframe = new mosMainFrame( $database, $option, '.' );
$mainframe->initSession();


insert this below that code:

Code: Select all

$mainframe->setPageTitle();


this addition makes up for the fact that some third party components don't call the setPageTitle function.  this way it is always called.

That should complete the hack!

Now log into the administrator end and change the "Custom Title Tag" parameters on your menu items and content items.  If you leave the parameter blank then Joomla will use the default Site Name and page Name as the Title.

Let me know if this works or doesn't.  Have fun.

-Barnett
Last edited by barnett on Tue Apr 25, 2006 5:28 pm, edited 1 time in total.
http://www.contemplatedesign.com/ - Joomla Development & Design

FiReStOrM
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Tue Oct 04, 2005 7:58 am
Contact:

Re: Custom Title Tag Hack for every page

Postby FiReStOrM » Thu Feb 09, 2006 8:53 am

great one for SEO . thx

Dom.S
Joomla! Apprentice
Joomla! Apprentice
Posts: 29
Joined: Mon Jan 16, 2006 2:18 pm
Contact:

Re: Custom Title Tag Hack for every page

Postby Dom.S » Thu Feb 09, 2006 12:49 pm

Great post, thanks. If people want to always have the site name in the title tag as well as the custom title then this code results in "$customtitle - $sitetitle" style title tags.

Instead of:

Code: Select all

$title = $custom_title ? $custom_title : $GLOBALS['mosConfig_sitename'] . ' - '. $title;


Put:

Code: Select all

$title = $custom_title ? $custom_title  . ' - ' . $GLOBALS['mosConfig_sitename'] : $GLOBALS['mosConfig_sitename'] . ' - '. $title;

Dehaw
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Thu Nov 10, 2005 4:32 pm

Re: Custom Title Tag Hack for every page

Postby Dehaw » Sun Feb 26, 2006 9:13 pm

Absolutely brilliant, now i need to get to work with my keywords and page titles  ;D

One thing - how do i make the content item name show before the site name?

I did already have a hack for it but can't find it.

djhomeless
Joomla! Apprentice
Joomla! Apprentice
Posts: 9
Joined: Mon Dec 26, 2005 12:07 pm

Re: Custom Title Tag Hack for every page

Postby djhomeless » Fri Mar 03, 2006 9:54 am

This is an excellent mod. No, this isn't a hack! :)

Really, I'm falling over myself how happy I am. Worked like a charm. Thank you so much!!!

Geoffrey

Dehaw
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Thu Nov 10, 2005 4:32 pm

Re: Custom Title Tag Hack for every page

Postby Dehaw » Wed Mar 08, 2006 1:56 pm

Dehaw wrote:Absolutely brilliant, now i need to get to work with my keywords and page titles  ;D

One thing - how do i make the content item name show before the site name?

I did already have a hack for it but can't find it.


I changed this line:

Code: Select all

$title = $custom_title ? $custom_title  . ' - ' . $GLOBALS['mosConfig_sitename'] : $GLOBALS['mosConfig_sitename'] . ' - '. $title;


to

Code: Select all

$title = $custom_title ? $custom_title  . ' : ' . $GLOBALS['mosConfig_sitename'] : $title .' : '. $GLOBALS['mosConfig_sitename'];


Now it shows the content name before the site name if there is no custom tag  ;D

cmdelivor
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 03, 2006 6:23 pm

Re: Custom Title Tag Hack for every page

Postby cmdelivor » Mon Apr 03, 2006 6:29 pm

I have incorporated your code upon your instruction but I don't seem to get the required result. The page title continues to work as it did: "Site name - Dynamic Page name" which makes me think that the parameters are not passed in correctly into the clause.
Any ideas anyone?
Chris

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Mon Apr 03, 2006 9:11 pm

cmdelivor wrote:I have incorporated your code upon your instruction but I don't seem to get the required result. The page title continues to work as it did: "Site name - Dynamic Page name" which makes me think that the parameters are not passed in correctly into the clause.
Any ideas anyone?
Chris


Do you have an example to look at?  Maybe also a screen capture of what it looks like for the administrator as well?  Tell us more about what version of Joomla you are using.  Have you modified your code before?

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

cmdelivor
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 03, 2006 6:23 pm

Re: Custom Title Tag Hack for every page

Postby cmdelivor » Tue Apr 04, 2006 2:59 pm

The domain is http://www.fuelture.com . It's currently running Mambo 4.5.3 and we're in the process of migrating to Joomla. I have some experience with core hacking before, so I'm pretty sure what I did was correct according to the instructions. and it seems to produce the right title for the webpage as if there were no parameters. I'm thinking that for some reason the clause for the parameters is not executed. But I can't tell, if that's the case, why the $params are not passed on correctly. The code lloks ok but it doesn't work for me.
Any pointers would be appreciated.
Chris.

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Tue Apr 04, 2006 7:21 pm

Are you running OpenSEF?  That may be the problem.

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

User avatar
kenmcd
Joomla! Champion
Joomla! Champion
Posts: 5672
Joined: Thu Aug 18, 2005 2:09 am
Location: California
Contact:

Re: Custom Title Tag Hack for every page

Postby kenmcd » Tue Apr 04, 2006 8:02 pm

barnett wrote:Are you running OpenSEF?  That may be the problem.

-barnett


1. OpenSEF does not run on Mambo 4.5.3

2. OpenSEF is not going to affect the code executed within that PHP file.

3. I have done various Title hacks with no problems.
██ LibreTraining

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Tue Apr 04, 2006 8:11 pm

@ kenmcd:  I like openSEF ;D but I just hadn't tested with this hack.  Thanks for clearing that up.

@ cmdelivor:  I've never tested this with Mambo 4.5.3, only 4.5.2 and all Joomla versions

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

cmdelivor
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Apr 03, 2006 6:23 pm

Re: Custom Title Tag Hack for every page

Postby cmdelivor » Wed Apr 05, 2006 1:17 am

I see. Thanks for your help guys. I think I will wait till we migrate to Joomla.
Cheers.

Scarpantibus
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Wed Dec 21, 2005 11:14 am

Re: Custom Title Tag Hack for every page

Postby Scarpantibus » Wed Apr 05, 2006 1:59 pm

Thank you very much for this hack!

I've tested it on Joomla 1.0.8 and the last release of OpenSEF and everything is ok.

Hope it will be implemented in next Joomla 1.5 release.

Thanks again,
Scarpantibus

muppy
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Nov 20, 2005 6:53 pm

Re: Custom Title Tag Hack for every page

Postby muppy » Wed Apr 05, 2006 2:16 pm

barnett wrote:
Now log into the administrator end and change the "Custom Title Tag" parameters on your menu items and content items.  If you leave the parameter blank then Joomla will use the default Site Name and page Name as the Title.



I can't find this parameter :o Where should it be?
Thanks
Andrea

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Wed Apr 05, 2006 3:04 pm

barnett wrote:1. Insert Custom Title Tag Parameters

add the following line of code as a childNode of the node

Code: Select all

<param name="title_cust" type="text" size="20" default="" label="Custom Title Tag" description="A custom Title tag to be applied to the page, this allows individual page titling" />

in the following .xml files:


administrator/components/com_menus/component_item_link/component_item_link.xml
and every subfolder under the com_menus/ directory that contains a .xml file. (ex. content_section/content_section.xml)

administrator/components/com_banners/banners.xml
and every subfolder under the administrator/components/ directory that contains a .xml installer file. (ex. com_frontpage/frontpage.xml)
Note: when you install a new component you will have to add the line of code to the component's .xml installer file


Did you follow this step correctly and add the param tag above within the code here tag in each .xml file for the menus and components?

It should appear then under the paramaters tab in content items as well as on the right in the parameters area when creating a menu item.

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

muppy
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Nov 20, 2005 6:53 pm

Re: Custom Title Tag Hack for every page

Postby muppy » Wed Apr 05, 2006 3:20 pm

barnett wrote:Did you follow this step correctly and add the param tag above within the code here tag in each .xml file for the menus and components?


I think yes. I post here: http://www.alientech.it/title.rar modified xml files. Can you check them?
Thanks!
Andrea

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Wed Apr 05, 2006 4:02 pm

Most of the files look correct.  I did notice on some where you were adding this as the first param that you didn't put it between the tag.  For example on banners.xml you have:

Code: Select all

<param name="title_cust" type="text" size="20" default="" label="Custom Title Tag" description="A custom Title tag to be applied to the page, this allows individual page titling" />
  <params />


but it should be this:

Code: Select all

<params>
<param name="title_cust" type="text" size="20" default="" label="Custom Title Tag" description="A custom Title tag to be applied to the page, this allows individual page titling" />
 </params>


Anyway take a look at one of your menu items (ex: a link to static content item) and you should see the parameter to your right when you edit the item.  I've attached a screenshot.

-barnett
You do not have the required permissions to view the files attached to this post.
http://www.contemplatedesign.com/ - Joomla Development & Design

muppy
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun Nov 20, 2005 6:53 pm

Re: Custom Title Tag Hack for every page

Postby muppy » Wed Apr 05, 2006 4:04 pm

I solved the problem.
Hint: don't open the files with dreamweaver 4.0: it alter code structure!
Thanks!
Andrea
Last edited by muppy on Wed Apr 05, 2006 4:06 pm, edited 1 time in total.

mattr2110
Joomla! Explorer
Joomla! Explorer
Posts: 273
Joined: Thu Feb 16, 2006 2:42 am

Re: Custom Title Tag Hack for every page

Postby mattr2110 » Wed Apr 05, 2006 11:14 pm

Once I did the custom title tag hack this no longer worked

http://forum.joomla.org/index.php/topic ... #msg176875

Does this work for anyone?

User avatar
pcigre
Joomla! Explorer
Joomla! Explorer
Posts: 338
Joined: Mon Sep 05, 2005 11:21 am
Location: Nis, Serbia
Contact:

Re: Custom Title Tag Hack for every page

Postby pcigre » Tue Apr 11, 2006 3:44 pm

Will this be implenetned in 1.5???
http://www.pcigre.com -> game community

User avatar
koestel
Joomla! Intern
Joomla! Intern
Posts: 96
Joined: Tue Nov 01, 2005 9:39 pm
Location: Mulhouse
Contact:

Re: Custom Title Tag Hack for every page

Postby koestel » Fri Apr 21, 2006 4:34 pm

does not go with mambo 4.5.2 Fr
the title are to record in menu but not enabled in frontend... ???
http://www.alsasys.com - Web Agency spécialisée dans les solutions libres pour les entreprises:

[X] Développement spécifique (Joomla / Oscommerce/ Magento)
[X] Conseil et formation
[X] Web design
[X] Référencement / e-marketing

limin
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Mar 24, 2006 4:03 am

Re: Custom Title Tag Hack for every page

Postby limin » Fri Apr 21, 2006 5:02 pm

Thanks so much for the hack.  I have it installed and it works pretty good, but it doesn't seem to work on all things.  I have a few menu items that the page title is not being rewritten from the default of sitename.

For example, I have a menu item defined that displays an item from the xtratings component which uses facileforms.  I edited the menu item to include a custom title but the custom title does not appear.  I have several other menu items behaving in the same manner. 

I am pretty much clueless to much of this, but I don't understand what the point of modifying all the XML files in the components subfolders was for.  Many of the components don't have a parameters page.  So there is no way to enter a custom title.

Adr|an
Joomla! Apprentice
Joomla! Apprentice
Posts: 5
Joined: Mon Apr 24, 2006 3:32 pm

Re: Custom Title Tag Hack for every page

Postby Adr|an » Mon Apr 24, 2006 3:58 pm

10x for the hack.

It works great on menu items but I can't find the "Custom Title Tag" parameter when I edit a content item. I have checked and I think I did everything ok. I am using Joomla 1.08. Can someone help me?

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Tue Apr 25, 2006 2:31 pm

@ Adr |an

  In step one of the hack did you include the paramater line in the following files:
  administrator/components/com_content/content.xml
  administrator/components/com_typedcontent/typedcontent.xml

  After you insert it there it should appear under the "parameters" tab of each content item and static content items.


@ limin
 
    What menu item type did you use?  I've noticed Link-URL will not work with this hack, I think.  But if there is a specific menu type for xtdratings then you should add the param line from step one into the com_menus .xml file for xtdratings.  What type are the other menu items you've noticed not working?

  You're right about the components.  Not all xml files need to be edited.  Only the ones that appear on the frontend like com_contacts, com_content, com_frontpage, com_typedcontent, etc...

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

limin
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Mar 24, 2006 4:03 am

Re: Custom Title Tag Hack for every page

Postby limin » Tue Apr 25, 2006 4:08 pm

The menu type that is not working is Component.  I have several defined in my top navigation and none of them work.  Each has a paramenter field that allows for the insertion of the custom title, but the custom title isn't getting rewritten to the page title.

I have double checked the com_menu/Components/components.xml for the proper entry.  This is what I have:


   
   



Which I think is correct.

User avatar
barnett
Joomla! Intern
Joomla! Intern
Posts: 76
Joined: Fri Aug 19, 2005 12:52 pm
Location: Nyack, NY

Re: Custom Title Tag Hack for every page

Postby barnett » Tue Apr 25, 2006 5:25 pm

limin wrote:The menu type that is not working is Component.  I have several defined in my top navigation and none of them work.  Each has a paramenter field that allows for the insertion of the custom title, but the custom title isn't getting rewritten to the page title.


Fixed it.  The reason it works for some components and not others is the fact that some don't call the setPageTitle function.  I've added a step #4 to this hack which will fix this issue.  See original post.

-barnett
http://www.contemplatedesign.com/ - Joomla Development & Design

limin
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Mar 24, 2006 4:03 am

Re: Custom Title Tag Hack for every page

Postby limin » Tue Apr 25, 2006 8:19 pm

Barnet;

Thanks very much for the update.  Step four seems to have solved the problem.

mattr2110
Joomla! Explorer
Joomla! Explorer
Posts: 273
Joined: Thu Feb 16, 2006 2:42 am

Re: Custom Title Tag Hack for every page

Postby mattr2110 » Tue May 02, 2006 3:46 pm

Is there a way to apply this to categories? Inside the admin there is no parameters" tab for categories.

limin
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Mar 24, 2006 4:03 am

Re: Custom Title Tag Hack for every page

Postby limin » Tue May 02, 2006 3:48 pm

That would be very nice.  Sections too!


Return to “Core Hacks and Patches”

Who is online

Users browsing this forum: No registered users and 0 guests