Canonicalization of php system

166 views Asked by At

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
?>
&ltlink rel="canonical" href="<?php echo $_canonical;?>" /&gt
<?php 
endif; // end check url match
endif;
?>
1

There are 1 answers

0
Kristoff Rand On BEST ANSWER

Error in php coding.

&ltlink rel="canonical" href="<?php echo $_canonical;?>" /&gt

should be

<link rel="canonical" href="<?php echo $_canonical; ?>" />

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/