我正在尝试让 rel=canonical 在我的网站上工作,这是一个名为tomatocart 的php cms 系统。
我正在使用这个 php 片段,它确实创建了正确的 url,但是它在页面上显示了 url,并且它没有将它放在它应该位于的 Head 区域中。规范化检查器看不到代码。
如何确保此代码显示在 head 标记中,以及如何将其从页面的正面隐藏?
<?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;
?>