The last notes
All English-language materials have been translated fully automatically using the Google service
Adding a canonical link through the settings of the complex component directory
If you have a standard component and template, then most likely you just need to add a parameter to the component call:
$APPLICATION->IncludeComponent(
'bitrix:catalog',
'catalog',
[
...
'DETAIL_SET_CANONICAL_URL'=> 'Y'
...
]
);
Add rel canonical to header.php
Alternatively, a canonical link can be added by cutting off all unnecessary from the url
$page = $APPLICATION->GetCurPage(true);
if (preg_match('/^\/catalog/', $curPage))
echo '<link rel="canonical" href="' . page . '" />';
or
<link rel="canonical" href="<?=$APPLICATION->GetCurDir(); ?>" />
Adding a canonical link via catalog component templates
In the result_modifier.php
file of the catalog.section
component, add at the very bottom:
$arSection = CIblockSection::GetById($arResult["ID"])->GetNext();
$arResult['SECTION_PAGE_URL'] = $arSection['SECTION_PAGE_URL'];
$cp = $this->__component;
if (is_object($cp))
$cp->SetResultCacheKeys(array('SECTION_PAGE_URL'));
Add to the component_epilog.php
file
$APPLICATION->AddHeadString('<link href="https://'.SITE_SERVER_NAME.$arResult['SECTION_PAGE_URL'].'" rel="canonical" />',true);
In the component template catalog.element
, proceed in a similar way. Add
result_modifier.php
file
$arElement = CIblockElement::GetById($arResult["ID"])->GetNext();
$arResult['DETAIL_PAGE_URL'] = $arElement['DETAIL_PAGE_URL'];
$cp = $this->__component;
if (is_object($cp))
$cp->SetResultCacheKeys(array('DETAIL_PAGE_URL'));
In component_epilog.php
add
$APPLICATION->AddHeadString('<link href="https://'.SITE_SERVER_NAME.$arResult['DETAIL_PAGE_URL'].'" rel="canonical" />',true);
Comments