
I am building a store using the Shopp plugin, and I noticed that there are possibilities for duplicate content issues:
- A product can be accessed both by
/shop/{productID}and/shop/{product-slug} - A tag can be accessed using
/shop/?shopp_tag={tag-uri}and/shop/tag/{tag-slug} - A tag can be accessed using
/shop/?shopp_category={category-id}and/shop/{category-uri}
Should Google somehow find it’s way into indexing these pages, the value of the identical indexed pages may drop. Canonical tags aim to remedy this situation, and are implemented by the hugely popular and awesome All in One SEO Pack plugin (see my other SEO tips regarding AIOSEO Pack plugin).
The Shopp plugin does not feature canonical tag support, so here’s a modification you can make that will add support for it without changing any core files in All in One SEO Pack, or in Shopp.
Add the following code to your theme’s functions.php file
function shopp_canonical_tag() {
global $Shopp, $aioseop_options; // The All in One SEO Pack Options Variable
// Get all the pages Shopp is using and make an array
$ShoppPages = $Shopp->Settings->get('pages');
$pages = array();
foreach($ShoppPages as $ShoppPage) { $pages[] = $ShoppPage['id']; }
// If in a Shopp page...
if(is_page($pages)) {
// Path to Shopp installation
$path = $Shopp->shopuri;
$link = '';
if($Shopp->Product->id) { // If in a product
$link = $Shopp->Product->slug;
}
elseif($Shopp->Category->id) { // If in a category
$link = $Shopp->Category->uri;
}
elseif($Shopp->Category->tag) { // If in a tag
$link = $Shopp->Category->slug.'/'.$Shopp->Category->uri;
}
elseif(isset($Shopp->Cart->data->Search)) { // If in a search result
$link = 'search/'.$Shopp->Cart->data->Search;
}
if($link) {
// Turn off All in One SEO pack canonical URLs for this page
$aioseop_options['aiosp_can'] = false;
// Add the proper trailing slashes to the link using this WP function
$link = trailingslashit($path.$link);
echo "\n\t".'<link rel="canonical" href="'.$link.'" />'."\n\t";
}
}
}
// Add the function to your site's <head> and run it before AIOSEO Pack
add_action('wp_head', 'shopp_canonical_tag', 1);
When Shopp tells this function that it is on a product, tag, search, or category page, it will show a canonical tag to that page. If Shopp doesn’t have an available page, it will leave it up to the SEO Pack plugin to show its canonical tag as usual (which works on the checkout, account, and other pages).
This code will set you up nicely for a SEO’d-out shopping cart. Leave feedback below!
Did this make your life easier? Was this information worth a buck?
Donate with PayPal (Much appreciated!)
Related posts: