Add Canonical Tags to Shopp Plugin for SEO

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 "nt".'<link rel="canonical" href="'.$link.'" />'."nt";
		}
	}
}
// 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!)

Author: Zack Katz

Zack Katz is the President of Katz Web Services and the developer of WordPress plugins with over 700,000 downloads. He lives in Southwest Colorado with his wife and two cats.

7 thoughts on “Add Canonical Tags to Shopp Plugin for SEO”

  1. good idea, bookmarked for future use. I’ve just started to use shopp, really enjoy it and look forward to building some amazing stores in it.

    ps your blog comment fields tab in a crazy order.

  2. Hi your post is amazing, It’s incredible, I learned a lot about SEO and Man, this thing’s getting better and better as I learn more about internet marketing. Also as part of my ongoing mission to find the absolute best tools to make money, this is without a doubt at the top of my list. Everything happened so fast!

  3. I am using Thesis. Any idea on how to add the above code to the custom-functions.php? I believe that the process is slightly different. Thanks!
     
     
     

Leave a Reply

Your email address will not be published. Required fields are marked *