From 934df0011f81dee75136cd1891450c2cc096330f Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 24 Feb 2026 15:10:16 +0100 Subject: [PATCH] FEATURE Handling page subtitles in secondary menu --- includes/navwalker.php | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/includes/navwalker.php b/includes/navwalker.php index 7ff2069..6aec031 100644 --- a/includes/navwalker.php +++ b/includes/navwalker.php @@ -7,9 +7,7 @@ function wrap_parent_menu_item_buttons($output, $item, $depth, $args) { - - // #### MENU HOMEGRADE HEADER - if ($args->theme_location === "secondary" && in_array('menu-item-has-children', $item->classes, true)) { + if ($args->theme_location === "secondary" && in_array('menu-item-has-children', $item->classes, true) && $depth === 0) { $output = ''; return $output; } @@ -22,23 +20,36 @@ function wrap_parent_menu_item_buttons($output, $item, $depth, $args) - if ($args->theme_location === "primary" && !in_array('menu-item-has-children', $item->classes, true) && $depth === 1) { + + if (!in_array('menu-item-has-children', $item->classes, true) && $depth === 1) { $page_icon = get_field('page_icon', $item->object_id) ?? null; $icon_html = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '' : ''; + $page_subtitle = get_field('page_subtitle', $item->object_id) ?? ''; $subtitle_html = '' . $page_subtitle . ''; + + if ($item->url === 'https://carhop.local/a-propos/equipe/') { + write_log($item); + write_log($subtitle_html); + write_log($icon_html); + // $icon_html = get_archive_page_icon_html($item->object); + // $subtitle_html = get_archive_page_subtitle_html($item->object); + } if ($item->type === 'post_type_archive') { $icon_html = get_archive_page_icon_html($item->object); $subtitle_html = get_archive_page_subtitle_html($item->object); } + if ($item->ID === 494) { + write_log($item); + } - - $output = '' . $icon_html . ''; + $output = '' . $icon_html . ''; return $output; } + return $output; } add_filter('walker_nav_menu_start_el', 'wrap_parent_menu_item_buttons', 10, 4); @@ -91,7 +102,8 @@ add_filter('nav_menu_submenu_css_class', 'tailpress_nav_menu_add_submenu_class', function carhop_add_submenu_item_icon($output, $item, $depth, $args) { // Only for submenu items (depth >= 1 - if (!isset($args->theme_location) || $args->theme_location !== 'secondary' || $depth < 1 || !function_exists('get_field')) { + if (!isset($args->theme_location) || $args->theme_location !== 'secondary' || $depth < 1 || !function_exists('get_field')) { + return $output; } @@ -102,19 +114,18 @@ function carhop_add_submenu_item_icon($output, $item, $depth, $args) return $output; } - $icon_html = ''; - $excerpt_html = ''; + $subtitle_html = ''; // Attachment array with ID (ACF image field) if (is_array($pageIcon) && isset($pageIcon['url'])) { $icon_html = ''; } - if (has_excerpt($item->object_id)) { - $excerpt_html = ''; + if (page_has_subtitle($item->object_id)) { + $page_subtitle = get_field('page_subtitle', $item->object_id); + $subtitle_html = '' . $page_subtitle . ''; } - - return '' . $icon_html . ''; + return '' . $icon_html . ''; } add_filter('walker_nav_menu_start_el', 'carhop_add_submenu_item_icon', 15, 4);