Forum Moderators: open
In joomla this can be a bit of a headache and we had issues with this because we did not wish to install a larger more complex commercial SEO tool for joomla, as we were happy with 90% of our own optimisations - we just wanted control over titles. This ended up being quite a simple / modest change to the joomla code (quite managable in future upgrades given the limited amount of change required):
=============
In order to accomplish this, do the following
1. OPEN components/com_content/content.php
2. LOOK FOR:
// page title
$mainframe->setPageTitle( $row->title );
3. CHANGE TO:
// 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
** NOTE: THIS MUST BE DONE IN 2 PLACES IN THE CONTENT.PHP FILE
4. OPEN includes/joomla.php file and look for:
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'];
}
}
5. Add the following function AFTER this (note: do not replace the setPageTitle function):
// 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 voila - if you haven't defined a Title_Alias for a static content page, then the default siteName - static-content-title format is used, however if you define a Title_Alias of greater than 20 chrs in length, then this becomes your page title. It has a nice little side effect too - that the title_alias field is just about the right length for a title tag.
This gives you great control over retaining the usefulness of title aliases as a means to identify static content pages with common titles, but giving you an easy way to configure separate page titles for SEO purposes.
I hope you joomla fans find this one useful.
Cheers all,
Phil B
Also, have you tested this with the pagebreak mambot for multipage articles?
I don't have access to my com_content hacks, but will post them here later today. We've modified it and default pagetitle function a fair bit (small tweaks here and there) to get a little bit more leverage.
Thanks for posting. :)
In my case, I like to keep my page titles shorter, and I'm greedy in wanting to employ the maximum <title> tag length and maximum use of important one and two word keyword combo's and so the title-alias gave me the greatest flexibility.....albeit a slightly messier looking static content item list ;-)
I also wrap the static content titles in a single <h1> tag (will post that snippet tomorrow).
I also hack the RSS.php file and the content.php and content.html.php files to get h1 tags on the page. I also use SEF Advance and JoomatWorks hacks.
If anyone hasn't seen the h1 tag hack sticky me and I will come back and post it.
All your hacks, and more are done by the SEF patch from Joomlatwork.com and there free as well.
[edited]
Hope this gives you even more control the easy way.
[edited by: shri at 11:57 pm (utc) on Dec. 28, 2006]
[edit reason] specifics edited as per TOS [/edit]
<td class="contentheading<?php echo $params->get( 'pageclass_sfx' );?>" width="100%">
<?php echo $row->title;?>
<?php HTML_content::EditIcon( $row, $params, $access );?>
</td>
....and then replace it with:
<td class="contentheading<?php echo $params->get( 'pageclass_sfx' );?>" width="100%"><h1>
<?php echo $row->title;?>
<?php HTML_content::EditIcon( $row, $params, $access );?>
</h1></td>
Enjoy. Also, re: joomlatwork patch, cool - if that does the job also, all good. Great to have options (from my brief look, it looks a little more involved that the simple change above....but it's probably done in a cleaner way).