Skip to content

Instantly share code, notes, and snippets.

@Isa3v
Last active January 15, 2025 13:27
Show Gist options
  • Save Isa3v/fe461020414c23fb7553ef6c0aed7099 to your computer and use it in GitHub Desktop.
Save Isa3v/fe461020414c23fb7553ef6c0aed7099 to your computer and use it in GitHub Desktop.
Пагинация в мета-тегах и h1 (Bitrix)

Пагинация в мета-тегах, h1 + canonical (Bitrix)

Задача:

*Добавить на страницах пагинации в title, description и h1 приписку с номером страницы

Решение:

*В bitrix/php_interface/init.php (если нет, то создаем) добавляем в конец функцию разбирающая мета-теги и собирающая обратно

Событие "OnEpilog" вызывается в конце визуальной части эпилога сайта. (После того как битрикс получит уже все данные страницы)

<?php
//Добавляем в конец init.php
AddEventHandler('main', 'OnEpilog', 'orPagenMeta');
function orPagenMeta() {
if ($page = preg_grep("/PAGEN_(.*)/i", array_keys($_REQUEST))) {
$page = intval($_REQUEST[reset($page)]);
// canonical
$GLOBALS['APPLICATION']->SetPageProperty('canonical',((!empty($_SERVER["HTTPS"])) ? "https://" : "http://") . $_SERVER['SERVER_NAME'].$GLOBALS['APPLICATION']->sDirPath ,true);
//h1
$GLOBALS['APPLICATION']->SetTitle($GLOBALS['APPLICATION']->GetTitle(false) . ' — Страница ' . $page;
//title
$title = $GLOBALS['APPLICATION']->GetProperty('title');
$GLOBALS['APPLICATION']->SetPageProperty('title', $title . ' — Страница ' . $page);
//description
$description = $GLOBALS['APPLICATION']->GetProperty('description');
$GLOBALS['APPLICATION']->SetPageProperty('description', $description . ' — Страница ' . $page);
}
}
@glsem
Copy link

glsem commented Dec 19, 2024

Все ок, спасибо! Только на 10 строчке пропустили скобку

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment