Joomla/Mambo Hack: Title Alias for Page Title

Here’s a cool hack that my web developers came up with that works well. It lets you use the feld "Title Alias" as the page title (HTML TITLE tag), giving you more control over page titles.

We’ll be going into 2 files. I’ll give the approximte line numbers here and I’ll be using Joomla.

File #1: components/com_content/content.php line 1140:

Remove this:

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

Replace with this:

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

File #2: includes/joomla.php line line 467:

Remove this:

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

Replace with this:

function setPageTitle( $title=null, $page_title=null ) {

global $mosConfig_pagetitle;

    if (@$GLOBALS[‘mosConfig_pagetitles’]) {

        $title = trim( htmlspecialchars( $title ) );

        $mosConfig_pagetitle= $title;

        if($page_title=="")

         $title=$title;

        else

          $title= $page_title;

        $this->_head[‘title’] = $title ? $title . ‘ – ‘.
$GLOBALS[‘mosConfig_sitename’] : $GLOBALS[‘mosConfig_sitename’];

    }

}

That’s it.  To prove it works, I’ve used "Change Page Titles in Joomla" for the Title Alias and "Joomla/Mambo Hack: Title Alias for Page Title" for the TItle.

Give it a shot. It’s best to comment old code so that you have it if you need it. If you do an upgrade, you may need to perform this again.