SEO for X-Cart – 4 simple modifications to optimise your store

post image

Recently the majority of e-commerce projects we have been working on here at Blueclaw have been using the x-cart platform and being a company that prides itself on its SEO services we strive to ensure the on-site optimisation of all the sites we produce is top notch.

While producing these sites there are a number of modifications we regularly carry out to the x-cart code to improve its already strong search engine optimisation and in this post and I will share some of my secrets so if you are running an x-cart shop you too can benefit from them.

Please note this tips are based on x-cart 4.4 if you need equivalent code for other versions just ask in the comments section below.

1. Homepage URL

The Problem

By default the URL of the homepage on any x-cart site is
http://www.mydomain.com/home.php
but we don’t like that,  the “home.php” is both a bit ugly and unnecessary and most importantly from a SEO point of view it leads to canonicalization issues as both http://www.mydomain.com/home.php and http://www.mydomain.com/ show the same page causing the search engines to see this as duplicated content.

The Solution

Ensure all homepage links point to http://www.mydomain.com/ (without the home.php) and amend our scripts to give a 301 redirect if anyone (or more importantly any search engine robot) tries to access http://www.mydomain.com/home.php

The Code

Edit home.php and add the following just after the “require ‘./auth.php’;” around line 52.
[sourcecode language=”php”]
if($_SERVER[‘REQUEST_URI’] == “/home.php”){
header (‘HTTP/1.1 301 Moved Permanently’);
header (‘Location: http://’.$xcart_http_host.’/’);
}[/sourcecode]

2. Fixing the breadcrumb

The Problem

Breadcrumbs are a useful tool for aiding customer navigation and helping them find their way home just like Hansel and Gretel, however it is this home link that is one thing we always like to change. Why you may ask, well by default the text within this link is “home” which while all very good in aiding the visitor in finding their way back to the home page it is not very descriptive to the search engine in what the homepage is about.

The Solution

We replace the “home” text with something more appropriate such as the site name and point it at http://www.mydomain.com/ rather than http://mydomain.com/home.php

The code

You can change the wording of the link without touching the code at all, within the languages admin you need to edit the entry called lbl_site_path and that will change the anchor text, it most cases the site name is the most suitable text for this.

To change the URL of this link you need to make the following amendment in /postauth.php around line 187.

Change this:
[sourcecode language=”php”]
if (!empty($lbl_site_name)) {
$location[] = array(
$lbl_site_name,
‘home.php’,
);
}
[/sourcecode]

To This:
[sourcecode language=”php”]
if (!empty($lbl_site_name)) {
$location[] = array(
$lbl_site_name,
‘/’,
);
}
[/sourcecode]

Of course this second change works in tandem with point 1 in preventing the homepage canonicalization issue.

3. Duplicate Titles

The Problem

In x-cart the page titles for products can be specified manually on a product by product basis, and when you haven’t entered a title x-cart will generate you a title based on the product/category name. That is however only until you specify the “Default site ‘Title’ tag” in the S.E.O. options, which (due to what I assume is a bug in the x-cart 4.4 code) overwrites the titles on all the product pages (that do not have a title manually set), with this default title.

The solution

I have got a little fix to the code that prevents this happening and prevents the auto generated titles being overwritten, if the Title has not been set for the product manually then instead of using the site default title we grab the product name and the name of the main containing category then create a title from this in the format  “Product Name – Category Name“.

The Code

/include/func/func.product.php around line 1582 (in the function func_get_product_title ) replace:
[sourcecode language=”php”]
if (empty($product[‘title_tag’]))
$product[‘title_tag’] = trim($config[‘SEO’][‘site_title’]);
[/sourcecode]
with:
[sourcecode language=”php”]
if (empty($product[‘title_tag’])){
$product = func_query_first(“SELECT $sql_tbl[products].product, $sql_tbl[categories].category
FROM $sql_tbl[products]
INNER JOIN $sql_tbl[products_categories] ON $sql_tbl[products].productid = $sql_tbl[products_categories].productid AND $sql_tbl[products_categories].main = ‘Y’
INNER JOIN $sql_tbl[categories] ON $sql_tbl[categories].categoryid = $sql_tbl[products_categories].categoryid WHERE $sql_tbl[products].productid = ‘$productid'”);
$product[‘title_tag’] = trim($product[‘product’]).’ – ‘.trim($product[‘category’]);
}
[/sourcecode]

4. Track Site Search

The Problem

The site search on x-cart by default uses the same URL regardless of the search. This means it is hard to track site search with tools such as Google Analytics and also means people are unable to link directly to a set of search results on your site. Now though this may not have much effect on your search engine rankings directly, being able to see what people are searching for on your site is very beneficial in seeing what search terms your visitors are interested in and helps you spot keywords to target that you may not have thought of before.

The solution

By altering the code slightly we can get x-cart to include the search term in the URL of the search results. Once the search term is being passed as a GET parameter to the results page it can then be captured by your Google Analytics code and with a little tweak to the account settings you can track what terms are being searched for.

The code

In the file include/search.php around line 200 change:
[sourcecode language=”php”]
$url = ‘search.php?mode=search&page=1’;
[/sourcecode]
To
[sourcecode language=”php”]
$url = ‘search.php?mode=search&page=1&q=’.$posted_data[‘substring’];
[/sourcecode]

Then to now track your site search in Google Analytics you need to amend the search part of the profile settings as follows:

Enabling Site Search in Analytics

Enabling Site Search in Analytics

Conclusion

If you follow all the above it should give your site a nice helping hand in climbing the Search Engine rankings, of course there is more that can been done both on site and off, so if you are interested in any SEO services or development work for your x-cart site then don’t hesitate to contact us.

about the author: ""
filed under: eCommerce / SEO Tips / Web Development | tags:
  • will this search trick work in 4.3.1
    >>mode=search&page=1&q=’.$posted_data[‘substring’];

  • John

    Can’t seem to lay my hands on a copy of the code from 4.3.1 just now, however in 4.3.2 the same change does work, although the code is around line 123

  • John

    Max, just tried the search on your site and it seems you have managed to implement this, so if you update the settings on your google analytics account too as shown, then it will begin reporting on the internal site search