This commit is contained in:
GP_DEV
2025-07-08 14:21:19 +03:00
parent a6bb81cbe1
commit 21562852ca
65 changed files with 7464 additions and 1073 deletions

View File

@@ -1,7 +1,6 @@
<?php
/**
* Навигационное меню с сео
* По умолчанию названию меню Шапка сайта
* Навигационное меню с SEO
*/
$menu = wp_get_nav_menu_object('Шапка сайта');
@@ -11,14 +10,13 @@ if ($menu) {
$current_lang = function_exists('pll_current_language') ? pll_current_language() : null;
if ($menu_items) {
// Чистим заголовок от (переводов)
$clean_title = function($title) {
return trim(preg_replace('/\s*\([^)]*\)/', '', $title));
};
$current_region = 'RU';
// Навигационная схема для Яндекса
$navigation_schema = array(
"@context" => "https://schema.org",
"@type" => "SiteNavigationElement",
@@ -28,13 +26,6 @@ if ($menu) {
"areaServed" => $current_region,
"url" => array()
);
// Хлебные крошки для Яндекса
$breadcrumb_schema = array(
"@context" => "https://schema.org",
"@type" => "BreadcrumbList",
"itemListElement" => array()
);
?>
<nav class="main-navigation primary-navigation h-full"
@@ -55,7 +46,7 @@ if ($menu) {
$url = $item->url;
$title = $clean_title($item->title);
// Polylang
// Polylang обработка
if ($current_lang && $item->object == 'page' && function_exists('pll_get_post')) {
$translated_page_id = pll_get_post($item->object_id, $current_lang);
if ($translated_page_id) {
@@ -67,15 +58,14 @@ if ($menu) {
}
}
// Дата изменения для Яндекса
// Дата изменения
$last_modified = '';
if ($item->object == 'page') {
$last_modified = get_the_modified_time('c', $item->object_id);
}
// Активный пункт меню
// Определение активного пункта
$is_current = false;
$current_classes = '';
$aria_current = '';
if (is_page()) {
@@ -84,7 +74,6 @@ if ($menu) {
if (($current_lang && function_exists('pll_get_post') && pll_get_post($item->object_id, $current_lang) == $post->ID) ||
$item->object_id == $post->ID) {
$is_current = true;
$current_classes = ' current-menu-item active current_page_item';
$aria_current = ' aria-current="page"';
}
}
@@ -102,14 +91,14 @@ if ($menu) {
if ($is_current) {
$css_classes[] = 'current-menu-item';
$css_classes[] = 'current_page_item';
$css_classes[] = 'active';
$css_classes[] = 'border-b border-b-[2px] !border-b-[#e21e24] dark:!border-b-[#fff]';
}
if (!empty($item->classes)) {
$css_classes = array_merge($css_classes, array_filter($item->classes));
}
// Схема для Яндекса
// Схема навигации
$page_data = array(
"@type" => "WebPage",
"name" => $title,
@@ -122,18 +111,11 @@ if ($menu) {
}
$navigation_schema['url'][] = $page_data;
$breadcrumb_schema['itemListElement'][] = array(
"@type" => "ListItem",
"position" => $position,
"name" => $title,
"item" => $url
);
?>
<li class="hover:translate-y-[-1px] transition h-full <?php echo esc_attr(implode(' ', $css_classes)); ?>" role="none">
<li class="h-full transition border-b border-b-[2px] border-b-[transparent] hover:border-b-[#e21e24] dark:hover:border-b-[#fff] <?php echo esc_attr(implode(' ', $css_classes)); ?>" role="none">
<a href="<?php echo esc_url($url); ?>"
class="menu-link !no-underline h-full flex items-center"
class="menu-link !no-underline h-full flex items-center"
role="menuitem"
itemprop="url"
tabindex="0"<?php echo $aria_current; ?>
@@ -143,7 +125,7 @@ if ($menu) {
onclick="if(typeof yaCounter !== 'undefined') { yaCounter.reachGoal('menu_click', {item: '<?php echo esc_js($title); ?>'}); }"
<?php if ($item->target): ?>target="<?php echo esc_attr($item->target); ?>"<?php endif; ?>
<?php if ($item->attr_title): ?>title="<?php echo esc_attr($item->attr_title); ?>"<?php endif; ?>>
<span itemprop="name"><?php echo esc_html($title); ?></span>
<span class="translate-y-[2px]" itemprop="name"><?php echo esc_html($title); ?></span>
</a>
</li>
@@ -151,11 +133,12 @@ if ($menu) {
// Сепаратор
if ($index < count($menu_items) - 1): ?>
<li class="menu-separator" role="none" aria-hidden="true">
<span class="separator"><svg width="7" height="15" viewBox="0 0 7 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.574219 14.4345L5.55022 0.5625H6.92622L1.93422 14.4345H0.574219Z"
class="fill-[#E0E0E0] dark:fill-[#F8F8F8] dark:opacity-20" />
</svg>
</span>
<span class="separator">
<svg width="7" height="15" viewBox="0 0 7 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0.574219 14.4345L5.55022 0.5625H6.92622L1.93422 14.4345H0.574219Z"
class="fill-[#E0E0E0] dark:fill-[#F8F8F8] dark:opacity-20" />
</svg>
</span>
</li>
<?php endif;
@@ -165,16 +148,12 @@ if ($menu) {
</nav>
<?php
// Cео
// Только схема навигации
?>
<script type="application/ld+json">
<?php echo json_encode($navigation_schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>
</script>
<script type="application/ld+json">
<?php echo json_encode($breadcrumb_schema, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>
</script>
<?php
}
}