Joomla JEA Canonical Link Problem with Duplicate Property urls

Joomla Estate Agency Canonical URL Problem, solved

Before reading this please note tht some php code has been stripped out of this article. I've included a zip of a text file at the bottom containing all the code

update #2 - I found a way to do this automatically in the end, the info is in the zip file. I'm going to leave the post though as it is still good for adding things like youtube videos.

I was seeing some funny things with a clients real estate site and webmastertools. Originally there were nearly 2000 pages indexed and showing up well in the search engines, which later dwindled to around 200 which could honestley be the amount of static pages on the site meaning the properties weren't being found (being ignored).

After starting a new site recently with 'joomla estate agency' I noticed a potential problem. This time I set up the site to have 1 main 'properties' menu link which then had child items refined to specic areas eg

All Properties
All Apartments
Rental Search
Sale Search

Also broken down by towns and areas, alot of places to go wrong. My boss then asked for yet more listings pages as 'landing pages'.

The Problem

The problem is not with the pages them selves, it's when you click through to a property from various places and end up with 20 urls for the same property, regarded as duplicate pages.

You could remove certain menu items from xmap which removes the duplicates from the sitemap but this of course doesn't mean google will ignore the others.

You could stop some urls in the robots.txt file but that defeats the point of trying to get the properties to the people who are looking for them faster.

The first idea I had was cononical links. I don't want to redirect people all over the site or have one big pool of places and only one form of search. So I thought it best to keep all my pages and add a canonical link to all of them to to point to the prefered version.

The Solution

So what I did (rather quickly, it's not elegant but it works) was to add an extra field in the add property page for the prefered url, which, if filled in will save to the database, it will then be inserted as a link in the head section of the page for every page this property appears on. It looks like this.

<link href="theUrlWhichIWant" rel="canonical" />

Searchengines will then know that this is a duplicate and to preferance the page in the link instead.

The Data Collection

I started with the backend property form located at: /administrator/components/com_jea/views/properties/tmpl/default_form.php

Create some new folders and move a copy of this file to here /administrator/templates/khepri/html/com_jea/properties/default_form.php

We can override the original file using this copy. Open it up and have a think about where you would like the input box to go. I added mine just under emphasis.

Find a suitable place and make sure you don't drop it the middle of something else. a


is a good sign. Then paste this in:

<td nowrap="nowrap"><label for="canonical">Canonical URL : </label></td><br /> <td width="100%"><br /> <input id="canonical" type="text" name="canonical" value="" class="inputbox" size="40" />


That will give us the input, now we add it to the database.


scrowl down and you'll see a big list of var values, add ours to the bottom of the list

var $canonical = null;

Next in /administrator/components/com_jea/models/properties.php

About half way down the file (250-270ish) there's a lot of JRequest statements, see that the bottom one has no comma after, so I just added mine second from bottom.

'canonical'       => JRequest::getVar( 'canonical' , '', 'POST' ),

Now the form is ready to send the info to the database, we need to add our field to the database.

Login to phpmyadmin or your method of choice, browse to your site database and select the table 'jos_jea_properties'

You should now see the list of fields. We need to add a new one so click on 'add 1 field at end of table go' and fill it out with the following data. (There are many blank fields)

field                    canonical
type                    VARCHAR
length/values      2083
collation             utf8_general_ci
null                     not null
mime type

Save it and it will now collect the data from the form (you can check by adding a url to a property and checking the database), we just need to output it

The Output

So now we just need to get the information into the head section on the property view pages.

To over-ride the responsible file copy /components/com_jea/views/properties/tmpl/default_item.php

to YOURTEMPLATEDIRECTORY/html/com_jea/properties/default_item.php

So now we check if the database has an entry for canonical and if so we attach our output to the document head.

I added this near to the top of the file under

JPluginHelper::importPlugin( 'jea' );?>



<?php if ( $this->row->canonical ): ?>




$document = &JFactory::getDocument();


$href =  $this->escape($this->row->canonical);


$document->addHeadLink( $href, 'canonical' );
<?php endif  ?>


Now when you add a property, publish it and browse to where to want it to be most prominant, maybe

Copy the whole domain name and paste it back into the canonical url box we just made for the property and save it.

Now, howver many urls a property may have, google knows where it actually should be.


To make this work with joomfish to have a different url for different languages, look in:


And add this line where ever you want it to show up in the translation order (but between the <table> tags!)

<field type="text" name="canonical" translate="1">Canonical URL</field

</p> <p> </p> <p>////**********Word of Joy******************////</p> <p>I have used this method in the past to do other fun things like add youtube videos to a property. Follow the first steps above but change the new field to 'youtube' and create a new database table to save it to. Then in your default_view.php file out put the video if one is stored.</p> <p><code><?php if ( $this->row->youtube ): ?><br /><br /><object width="650" height="350"><br /> <param name="movie" value=""></param><br /> <param name="wmode" value="transparent"></param><br /> <embed src="" type="application/x-shockwave-flash"
wmode="transparent" width="425" height="350"></embed><br /></object><br /><br /</p> <p>Code keeps getting stripped out here so you can download a zip of the real contents <a href="downloads/canonical_ blog_post.rar">here