Forum Moderators: open

Message Too Old, No Replies

Joomla SEO Page Title uses title-alias

         

pbaddock

10:17 am on Dec 12, 2006 (gmt 0)

10+ Year Member



For those of us who use Websites built on Joomla v1.0.x, who come to perform search engine optimisation on their sites.....while there are a lot of free tools (Artio/Open SEF) which assist with greater control over Joomla website URL's, one of the most important SEO factors these days is the ability to setup unique page titles which reflect the content of each page.

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

shri

10:29 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Using the title alias might be problematic if you're using Emir's Advanced SEF.

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. :)

shri

10:30 am on Dec 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> $this->_head['title'] = $title? $GLOBALS['mosConfig_sitename'] . ' - '. $title : $GLOBALS['mosConfig_sitename'];

This should be changed so that the $title is shown before the sitename.

I tend to prefer the "Article Title - Site Name" format over "Site Name - Article Title" format.

pbaddock

12:41 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



Yes - I think your suggested approach works well when
a) the sitename is kept short, and focused on the brand and one or two keyword combo's only and
b) the article/page titles are longer and more descriptive.

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).

pbaddock

8:49 pm on Dec 12, 2006 (gmt 0)

10+ Year Member



(I realised I should clarify in my previous post that by "page title" I'm referring to the CMS field for the static content page title field as opposed to <title> ....ie my on-page title shown at the top of the static content page, I like to keep shorter - but the <title> I like to leverage to the max as I've witnessed how much impact it has on google in particular including sequence of keywords used).

BillyS

12:03 am on Dec 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use a total of four hacks in Joomla - two of them were just mentioned.

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.

Hummerbie

7:45 pm on Dec 28, 2006 (gmt 0)

10+ Year Member



Why hack all those files, and still be left with troublesome issues in the menu and categories?

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]

BillyS

9:45 pm on Dec 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hummerbie - Yikes, those sites don't even validate anymore and have obvious errors in code leading to artifacts on the page - there's even a bit of spam on the page too.

They've also got images lined up with Adsense - another no-no.

pbaddock

4:07 am on Jan 4, 2007 (gmt 0)

10+ Year Member



Just to complete the post, to wrap your static content titles in a <h1> tag for some more SEO love, look in components/com_content/content.html.php for:


<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).

shri

5:08 pm on Jan 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't put the EditIcon nonsense in the H1 tag. Move the /H1 closer to the actual title.

Promise .. when I'm a awake, I'll post my mambo / joomla mods. About 5 or 6 of them that are not documented here.

pbaddock

8:13 am on Jan 7, 2007 (gmt 0)

10+ Year Member



Fair point re: editicon. Tks. (bit sloppy of me).

Anyway - hopefully the <h1> tip helps a few joombers too.