WP e-Commerce Search Engine Optimization
Update:
This post was originally written in March of 2008. A lot has changed with WP e-Commerce in that time. We’ve been keeping up with the changes and recently rewrote our WP e-Commerce SEO manual.
The post below may still have useful information, but certain portions like the title tag recommended below are no longer compatible, the manual is the most up to date information available. In it you’ll learn the secrets to speeding up your cart, how to set your title tags, how to make those invaluable xml sitemaps work and much more.
I’ve done quite a few posts lately on WordPress e-Commerce. I’ve looked for other solutions, but the truth is there’s nothing better out there at the moment and Instinct has done a lot of things right with this cart. Unfortunately, they haven’t had a lot of time to focus on optimizing it for search engines.
If you want the items in your WP e-Commerce site to show up in the search engines, you are going to need to do a little work. This post should help to improve your Web site’s store rankings; however, read the disclaimer at the end of this post prior to implementing any of these solutions.
Title Tag
The title that WP e-Commerce displays is probably responsible for 85% of WP e-Commerce’s search engine optimization deficiency. If you fix nothing else you should fix this issue. My solution is to work with the title tag which actually resides not in the WP e-Commerce plugin files but instead is located in your theme’s header.php file. To find it you’ll need to have access to your WordPress files on your hosts server. The path will look like wp_content/themes/yourtheme/header.php (where your theme is the actual name like “Classic”).
Make sure you save a copy of your header.php file, before you modify it, to your computer. This way if anything goes wrong you’ll be able to simply upload the original file and revert back to status quo.
Open the header.php file and find the title tag which will look something like this: <title><?php bloginfo(’name’); ?><?php wp_title(); ?></title>
Copy and paste the code on the following page in its entirety directly over your original tag from <title> to </title>.
<title><?php
function oGetProductName( $meta ){
global $table_prefix;
$query = “SELECT product_id
FROM “.$table_prefix.”wpsc_productmeta
WHERE meta_value = ‘”.$meta.”‘”;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$productid = $row[0];
$query = “SELECT name
FROM “.$table_prefix.”product_list
WHERE id = “.$productid;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$productname = $row[0];
return $productname;
}
function oGetCategoryName( $nicename ){
global $table_prefix;
$query = “SELECT name
FROM “.$table_prefix.”product_categories
WHERE `nice-name` = ‘”.$nicename.”‘”;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$categoryname = $row[0];
return $categoryname;
}
if( is_page() && trim(wp_title (”,false )) == ‘Products Page’ ){
$pparts = explode(’/', trim($_SERVER['REQUEST_URI'],’/') );
if( $pparts[2] != ” ){
echo oGetProductName( $pparts[2] );
}
else if( $pparts[1] != ” ){
echo oGetCategoryName( $pparts[1] );
}
else{
wp_title (”); echo ‘ at Your Site Name’;
}
}
else{ if ( is_single() ){ wp_title(”); }elseif (is_404()){ echo ‘Your Site Name – 404 Error’;
}elseif (is_category()) { echo single_cat_title(); echo ‘ at Your Site Name’; }elseif (is_page()) {
wp_title (”); echo ‘ at Your Site Name’; }else{ echo ‘Your Site Name’; }
}
?></title>
That’s it. Save the file and you’ve improved the seo on your shopping cart by a good eighty-five percent. *Note the above was worked out on the 3.6 Beta 12 release and may or may not work in other versions. The script has been worked out on WP 2.5. You can see it on one of my most recent projects www.alpenglownaturalfoods.com
Search Engine Friendly URL’s / Permalinks
Earlier versions of WP e-Commerce didn’t support keyword rich URLs. It is unknown what if any effect this plays in getting your site ranked higher in the search engines. However, your URL is known to be an important factor in people clicking through to your site from the search engines. Also the solution is very simple so you might as well implement it.
Within your WordPress admin area you will want to navigate to “Options” if you are using a pre 2.5 version of WordPress and “Settings” if you are using WordPress 2.5+. From either of these you will want to navigate to “Permalinks.” Scroll down the page and click the “Custom Structure” radio button and enter the following:
/%category%/%postname%/
I recommend you do this prior to setting up any category or product in your shopping cart as more than one WP e-Commerce user has found that they had to go back and do a fresh install of WP and / or WP e-Commerce when they didn’t do this option first. In fact you may want to do it prior to activating the plugin. WARNING – if you already had content on your blog or site but haven’t been using this option you will want to carefully consider how to move forward as changing now will change the URLs, cause you to have 404 errors, and lots of other problems. You do have other options. You can have more than one install of WordPress on a site, you can do 301 redirects, etc, but any of these may be a bigger headache than they are worth depending on your knowledge and comfort with any of them.
Modifying Category Pages
One of the annoying and seo unfriendly things that happens on the category pages of WP-eCommerce is that it shows all the categories. This means if you are clothing store you could get, blouses, trousers, shoes and more all showing up on the category page in anchor link text. This can confuse the search engine about what the page topic actually is and lead to lower rankings.
To get rid of the word “Category” and the list of categories that appears on individual Category pages remove this code:
//include(”show_cats_brands.php”);
if (get_option(’cat_brand_loc’) == 0) {
show_cats_brands();
}
from the products_page.php. The full path of which is wp-contetnt/plugins/wp-shopping-cart/products_page.php.
The default menu set up for WP e-Commerce shows in your “Pages” menu, and looks like:
- Catalog
- Verify your Order
- Transaction Results
- Your Account
From an SEO perspective this is very weak. Here there is already a solution provided by WP e-Commerce. Navigate to your “Widgets” within WordPress. This will be found under “Presentation” in pre WP 2.5 versions and under “Design” in 2.5 and above. There is a Categories and Brands widget and you can either drag this into your sidebar in the pre 2.5 WP or click Add in the post 2.5 versions.
Menu Header Title
This next piece may be a small SEO matter, but it is also a personal preference on presentation. The menu item using the above widget will read “Categories and Brands” in the header. You may want to rename it. I would. To do so navigate to the “languages” folder in wp-shopping-cart. wp-content/plugins/wp-shopping-cart/languages. Now find the file En_en.php open it and go down to the line that reads define(’TXT_WPSC_CATSANDBRAND’, ‘Categories & Brands’); You can edit the word “Categories” “Brands” to read whatever you like. Just make sure that if you are trying to use the ampersand “&” that you leave the “&” and that you leave in place the single quotation marks.
Update:
Here’s a revision to the title tag script that includes your category name before the product name on individual product pages. It was made at John’s request (see comments below) and I hope it helps others as well.
<title><?php
############################################################
## Custom Hack for wp-shopping-cart3.6Beta12 ##
## Just Copy this Section in between the <title> tag ##
## of your selected theme. Replace whatever code ##
## is in there. themes located ##
## at <wordpressroot>/wp-content/themes/<yourtemplate>/ ##
## Find the file header.php Mar.24,2008 ##
############################################################
function oGetProductName( $meta ){
global $table_prefix;
$query = “SELECT product_id
FROM “.$table_prefix.”wpsc_productmeta
WHERE meta_value = ‘”.$meta.”‘”;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$productid = $row[0];
$query = “SELECT name
FROM “.$table_prefix.”product_list
WHERE id = “.$productid;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$productname = $row[0];
return $productname;
}
function oGetCategoryName( $nicename ){
global $table_prefix;
$query = “SELECT name
FROM “.$table_prefix.”product_categories
WHERE `nice-name` = ‘”.$nicename.”‘”;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$categoryname = $row[0];
return $categoryname;
}
if( is_page() && trim(wp_title (”,false )) == ‘Products Page’ ){
$pparts = explode(’/', trim($_SERVER['REQUEST_URI'],’/') );
if( $pparts[2] != ” ){
echo oGetCategoryName( $pparts[1] ).’ ‘.oGetProductName( $pparts[2] );
}
else if( $pparts[1] != ” ){
echo oGetCategoryName( $pparts[1] );
}
else{
wp_title (”); echo ‘ at Daisy Marketing’;
}
}
else{
if ( is_single() ){
wp_title(”);
}elseif (is_404()){
echo ‘Daisy Marketing – 404 Error’;
}elseif (is_category()) {
echo single_cat_title(); echo ‘ at Daisy Marketing’;
}elseif (is_page()) {
wp_title (”); echo ‘ at Daisy Marketing’;
}else{
echo ‘Daisy Marketing’;
}
}
############################################################
## Custom Hack for wp-shopping-cart3.6Beta12 ##
############################################################
?></title>
Disclaimer:
I hope the above is useful for you. Just understand that you use it at your own risk. I am not making any claims that it will improve and not hurt your rankings or break your WP template.

Hi Guys.
First of all thanks for writing about WP e-Commerce. Making our plugin SEO friendly has been on our mind for a long time – hence adding permalink friendly support in the first place.
Regarding your first point on title tags, I’m not sure that is our fault. This is a limitation of WordPress. Thanks for the fix though David I’m sure people will find it useful.
Anyway, thanks again for the write up. I will act on your comments accordingly.
Also if you want to email me personally I’d love to chat about some SEO strategies for the main Instinct site.
Ciao,
Dan
Hi Guys. Thanks for the post – here are some comments on each items.
Title Tag
The way WordPress handles title tags is not something we can fix. I think you should mention this in your post – I don’t want people to get the wrong idea.
Search Engine Friendly URL’s / Permalinks
Luckily for you guys newer versions of WP e-Commerce support WordPress permalinks – we’ve been told by litereally hundreds of users that this alone makes the WP e-Commerce solution one of the best for SEO.
I personally use just:
/%postname%/
I do this because I read somewhere it was a good option. I’m open to suggestion though – if your option is better can you please explain why because I want to make sure that I am utilizing best practices.
The other thing to mention here is that you should also use a good theme in general, have an XML sitemap, and use something like the All in One SEO plugin.
Modifying Category Pages
I like what you have to say re using the Cats and brands widget.
If you think I should remove the following:
Products Page
- Verify your Order
- Transaction Results
- Your Account
Where should we put it instead of? We think its reasonable that you will want to goto each of these pages. Especially if you are a return buyer – the Your Account page is where you can quickly make similar purchases again. I’m keen to know your thoughts on this.
Menu Header Title
Can you please explain why this is a good practice. I’m not sure why ‘&’ is any better then ‘and’ – if I understand why then I’ll probably do it
Thanks heaps for your post!!!
Regards,
Dan
Dan is mostly correct that the title tag is a WordPress issue, or more specifically a theme issue. You can fix the title tag to be more seo friendly and that’s what using the title tag script I’ve provided will do, but you must do so in each WordPress theme.
The problem I see is that the way Instinct has built the cart is really restrictive since WP only sees it as a single page. I think they could come up with a different solution and exponentially increase the flexibility of the shopping cart.
I would like to see this info:
- Verify your Order
- Transaction Results
- Your Account
either in the shopping cart area – that makes the most sense to me, or as an additional sidebar item.
I can see how I wasn’t clear in the menu header title. It isn’t really about and vs. & (except as that relates to space. The real issue is that “Categories and Brands” doesn’t necessarily say clearly what the menu is about. Every time you create a question in a visitor’s mind you stand a chance to loose them (great advice from the book “Don’t Make Me Think“) so I’ve changed it to “Purchase Online”. As I said in the post I think this is a matter of individual preference.
Thanks to Dan for stopping by. I know he’s watching this post, so if you have anything to add to the discussion we’d love for you to join in.
Hello,
there are some issues with the code in the title section …
Parse error: syntax error, unexpected T_STRING in in header.php at line 11.
blowfish, if you want to send me line 11 from your header.php – I’ll take a look. This is working smoothly on other sites.
hey david,
Glad to see you helping with the Wp Ecommerce support…all help is gladly welcomed!!
Kevin – the side by side display requires their grid module which only works with their gold cart module. Once you have those two it should be no problem.
Make sure you’re choosing the side bar widget option for the shopping cart. This should clear it off the center column.
As for 3.5.1, you may have found a limitation. As I mention in the post, it has only been tested on 3.6 in the beta 12 version.
Hope that’s somewhat helpful.
Thanks for the info David.
If you do test it on ver 3.5.1 in future or happen to know someone who succesfully implemented your code on it, would appreciate if you could let me know. =)
Ciau David.
The script is running on http://webshop.tattoo-sfinx.ro. I’m not able to get the category name and the product name exported into the title page.
Can you please provide me some additional infos.
Thank you.
How about when pagination is used – throws a error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Hi your titles worked for me with the latest one change I used to have that quit working and I can not find what I changed.
What I had was
an individual post had “postname – found in categoryname” I can seem to get the categoryname variable right now. Any ideas?
Each post is only in one category.
TD, you’re correct about the pagination issue, also anyone using brands will find that it doesn’t work for brands even though it will work with categories. If I have an upgrade I’ll let you know.
John,
Nice site http://www.painrelief101.com/index.php. Did you mean that it works in wp 2.5?
I’ll look into the category issue and let you know if I come up with something.
Yes I am using WP 2.5 I have not upgraded to 2.5.1 yet. I would appreciate any ideas
John,
Above is a revision that should work for you. It shows category then product. Great idea on your part.
Hi David,
Thanks for all the work you’ve put into making WP e-Commerce a little less clunky as SEO goes.
I was attempting to install the revision you’d included above (already had the older one in place & thought I’d trade up). Initially, I was receiving errors because of a difference in text formating (ie ”‘” needing to be “‘”, etc).
I managed to clear those up (compared with the original and got what look to be the appropriate markings). Now I’m not getting any PHP errors, but the categories aren’t showing up with the item names in the Title bar, which I was assuming was the point of the whole excercise.
Any thoughts on what I might be doing wrong or what I might be missing?
Just a quick update. A big part of my problem was that I hadn’t turned off the All In One SEO options for the Products Page. That’s off now & the patch is _trying_ to work. It’s listing the product name in the title & afterwards says “at PaperStreet Supplies” (nifty!), but nowhere does it display the category information. I can’t spot anything obvious in the code (I’m no coder though) & thought I’d run it by you to see if you might be able to offer any advice.
Hi David, great work with the site and this post.
I am currently working on an e-commerce site for a client and I have a similar error to blowfish. When I copy/paste the code as my new title tag I get the following error:
“Parse error: syntax error, unexpected T_STRING in /home2/promedi5/public_html/ambnb/wp-content/themes/NEW-AMBNB-Theme/header.php on line 19″
The site can be found at ambnb.promediadigitaldesign.com
Any help in this will be more than appreciated. Let me know if there is anything else you need.
Many thanks
Additional details: line 19 in my code is this line:
$query = “SELECT product_idI can’t see why I get the parse error but noone else does =[
Any ideas why this would be occurring? Here is my entire head section:
<html xmlns="http://www.w3.org/1999/xhtml" >
<meta http-equiv="Content-Type" content="; charset=" />
<meta name="generator" content="WordPress " />
<link rel="stylesheet" href="" type="text/css" media="screen" />
<link rel="alternate" type="application/rss+xml" title=" RSS Feed" href="" />
<link rel="pingback" href="" />
Sorry! I think the comments are word count limited and the rest of my code and code close tag didn’t post. David, I can email you the code if need be. Thanks again
Update: I have removed the code from my title tag for the time being and just reverted back to the normal WP title code. (Just wanted to let you know in case you went there and it looked like the error was gone… it’s not
Also, I tried playing around with the semi-colons, double-quotation marks and sqiggly brackets to try removing the error but had no luck.)
Hi Nathan,
Sorry, I was away for the weekend. You can email me the code if you like and I’ll take a look.
Hi David,
thats all good. For some reason (unbeknown to me) I removed your code and replaced it with my original title code and now it is just displaying the product name in the title anyway???
My title code is:
» Blog ArchiveSo I am not sure what is going on really but somehow it is working? Or am I missing the point somewhere here? I almost feel like I must be!
Poo on a stick. It didn’t let me copy my code in correctly (again). I can email you the code if you are interested in looking at it for fun.
VERY helpful post. I modified your code slightly to query some custom fields to display the on product pages. Happy to share if anyone wants to email me. Works like a dream. Thanks so much.
I for one can’t wait to see what David has done to modify the code. Without even seeing it, and just knowing David’s reputation, I have no hesitation recommending that you take him up on his offer to share the code, I will be.
Hi David,
Thanks for your useful info on SEO for WP E-commerce. I found your posts while researching and playing with it myself, looking for a simple shop system with the many SEO benefits of a well coded WP site.
In the short time I have played with it, I can see many of the SEO shortcomings and have yet to make up my mind whether to pursue it. I am still not sure about the amount of extra work needed to hack the shop for optimum SEO, especially as I am not a natural code monkey. Here are are few of my bugbears:
* Title tags (thanks for your hacks on that)
* Semantics – “titles” on product pages don’t seem to be wrapped in H tags.
* Attempts to sculpt PR flow look like a lot of work. ( I know that opinion might be divided on the efficacy of this but IME this really does work)
Oh well, only 1 hour into it so far. My initial thoughts to “clean up” one thing was to change the products-page slug to /buy/. bit prettier and “bold up” well in SERPS.
Subscribed to your feed for this valuable insight. Thanks
Rob
wonderfull tutorial. now my site getting better
I am getting the same problem as David!…
Parse error: syntax error, unexpected T_STRING in /home/impecsac/public_html/sitios/jardinoculto/wp-content/themes/CraftyCart/header.php on line 8
In the line 8 it says: “$query = “SELECT product_id”
What could it be?
@Juampi
With the newest versions of wp e-commerce you should not need to change the title tag as they’ve built in a good one. If you’ve changed the title tag and you’re getting this message try replacing it with the original. If you’re keeping my custom title tag and you’re getting this, chances are that either a ; got dropped or characters like ” got changed by your editor when you copied it. Try striping the formatting of the title tag and inserting it.
dreaded T_STRING issue,
and no they did not fix it to work properly with title tags years later
Thanks for your tutorial
I cannot for the life of me get this to work.
Can you please email me, I’d love to get this thing going.
Checklist for Mentalists
1.Make sure you have downloaded latest WP ECommerce 3.7.4
2.Make sure you have the latest All in One SEO
3.Now log into wordpress deshboard and check this setting.
Products>settings>Presentation>Replace Page Title With Product/Category Name: yes
4. Set custom permalinks to /%category%/%postname%/
5. You will then have a Title Tag for wach product and google will love you
This solution suggested by Eoin does not work. I’ve tried to find another solution to edit the page title but i can’t find one. Anyone an idea?
Thanks!
@M.Kraan Eoin was a bit simplistic in that explanation there is much more to optimizing for search engines than this.
For your specific problem are you speaking of editing the page title or the “title tag” two different things obviously and I am not sure which you’re looking to get a solution for.
Hi David,
I’m looking to edit the page title (meta tag) of the homepage of http://www.valentijn-cadeaus.nl. All in one SEO doens’t provide a solution. I sort of figured out the reason.
The website is of course wordpress with the wp ecommerce plugin. My post page is set to a subpage (not home page) en the front page is a static page, namely the products page.
Wp ecommerce is loaded inside a page, so it doesnt ’see’ the difference between say the home page and a product detail page. So commands like ‘if_home’ or ‘if_front_page’ don’t apply for editing the title tag. Also the seo title tag plugin doens’t fix this problem.
So my challenge is to give the home page another title tag, while the product categorie pages, and product detailpages have the ‘page title’ as (meta) title tag.
I hope i made myself clear. Thanks for the quick respons! Greetz, Martijn