I'm trying to get rel=canonical to work on my site, a php cms system called tomatocart.
I'm using this php snippet which does create the correct url, however it shows the url on the page and it does not place it in the Head area where it should be. Canonicalization checkers do not see the code.
How can I make sure this code shows up in the head tag and how can I hide it from the front side of the page?
<?php
if (($osC_Template->getGroup() == 'products') && ($osC_Template->getModule() == 'products')):
// display canonical link
if($osC_Product->isValid()):
$_canonical = osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID(), 'AUTO',false, true, true);
else:
$_canonical = '';
endif;
if($_SERVER['REQUEST_URI'] !== $_canonical && $_canonical !== ''): // check if url is not match with canonical and not empty
?>
<link rel="canonical" href="<?php echo $_canonical;?>" />
<?php
endif; // end check url match
endif;
?>
Error in php coding.
should be
now canonical tags are hidden from front page and show up in header, also pass canonical test.
http://www.seoreviewtools.com/canonical-url-location-checker/