// Force robots meta for catalog category and subcategory pages. AddEventHandler("main", "OnEndBufferContent", "glinkiSetCatalogSectionRobots"); function glinkiSetCatalogSectionRobots(&$content) { if (defined("ADMIN_SECTION") && ADMIN_SECTION === true) { return; } $requestUri = $_SERVER["REQUEST_URI"] ?? ""; $path = parse_url($requestUri, PHP_URL_PATH); if (!$path || strpos($path, "/catalog/") !== 0 || substr($path, -1) !== "/") { return; } $codePath = trim(substr($path, strlen("/catalog/")), "/"); if ($codePath === "") { return; } if (!CModule::IncludeModule("iblock")) { return; } $sectionId = CIBlockFindTools::GetSectionIDByCodePath(31, $codePath); if (!$sectionId) { return; } $section = CIBlockSection::GetList([], ["IBLOCK_ID" => 31, "ID" => $sectionId], false, ["ID", "SECTION_PAGE_URL"])->GetNext(); $sectionPath = $section ? parse_url($section["SECTION_PAGE_URL"], PHP_URL_PATH) : ""; if ($sectionPath !== $path) { return; } $meta = ''; if (preg_match('/]*name=["\']robots["\'][^>]*>/i', $content)) { $content = preg_replace('/]*name=["\']robots["\'][^>]*>/i', $meta, $content, 1); } else { $content = str_replace('', "\t".$meta."\n", $content); } }