0
我在我的WordPress/WooCommerce網站上輸出規範標籤時遇到了一些麻煩。PHP如果is_product回聲規範鏈接
所以基本上,我們有幾個相同的產品設置爲簡單產品的變化。正因爲如此,我們有重複的內容,所以我們要告訴搜索引擎,信息的主要來源是我們通過規範標籤爲每個產品設置的着陸頁。
這是我們目前的代碼示例。所有的代碼是在我們的header.php文件:
<?php
// Achilles Desert Hawk UHP
if(is_product(array('245-40-r20-99v-achilles-desert-hawk-uhp-e-c-72', '245-45-r20-99v-achilles-desert-hawk-uhp-e-c-72', '255-45-r20-105v-achilles-desert-hawk-uhp-f-c-72')))
{
echo '<link rel="canonical" href="https://tyresdirectuk.co.uk/achilles-tyres/desert-hawk-uhp/" />';
}
// General Grabber GT
elseif(is_product(array('195-80-r15-96h-general-grabber-gt-e-c-71', '205-70-r15-96h-general-grabber-gt-e-c-71', '205-80-r16-104t-general-grabber-gt-e-c-72', '215-60-r17-96h-general-grabber-gt-e-c-71', '215-65-r16-98h-general-grabber-gt-e-c-71', '215-65-r16-98v-general-grabber-gt-e-c-71', '215-70-r16-100h-general-grabber-gt-e-c-71', '225-55-r17-97v-general-grabber-gt-e-c-71', '225-55-r18-98v-general-grabber-gt-e-c-71', '225-60-r18-100h-general-grabber-gt-e-c-71', '225-65-r17-102v-general-grabber-gt-e-c-71', '225-70-r16-103h-general-grabber-gt-e-c-71', '235-50-r18-97v-general-grabber-gt-e-c-71')))
{
echo '<link rel="canonical" href="https://tyresdirectuk.co.uk/general-tyres/grabber-gt/" />';
}
// Kumho Road Venture AT KL78
elseif(is_product(array('30-950-r15-104s-kumho-road-venture-at-kl78-f-e-78', '195-80-r15-100s-kumho-road-venture-at-kl78-e-e-74', '205-75-r15-97s-kumho-road-venture-at-kl78-e-e-74', '205-80-r16-104s-kumho-road-venture-at-kl78-e-e-74')))
{
echo '<link rel="canonical" href="https://tyresdirectuk.co.uk/kumho-tyres/road-venture-at-kl78/" />';
}
?>
所以基本上,問題是,相應的規範鏈接不被輸出到正確的頁面。
下面是一個例子:https://tyresdirectuk.co.uk/shop/tyres/205-75-r15-97s-kumho-road-venture-at-kl78-e-e-74/
這應該有代碼的<head></head>
標記之間以下行:
<link rel="canonical" href="https://tyresdirectuk.co.uk/kumho-tyres/road-venture-at-kl78/" />
而是它說:
<link rel="canonical" href="https://tyresdirectuk.co.uk/achilles-tyres/desert-hawk-uhp/" />
如果任何人都可以請指教對此,將不勝感激,因爲我不知道它:)