REFACTOR Refining primary menu wrapping
This commit is contained in:
parent
1310eedfef
commit
51b8db7592
|
|
@ -6,21 +6,38 @@
|
|||
|
||||
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)) {
|
||||
$output = '<button type="button" class="menu-item__submenu-toggle" aria-expanded="false" aria-controls="sub-menu-' . $item->ID . '">' . $item->title . '</button>';
|
||||
return $output;
|
||||
}
|
||||
if ($args->theme_location === "primary" && in_array('menu-item-has-children', $item->classes, true)) {
|
||||
if ($args->theme_location === "primary" && in_array('menu-item-has-children', $item->classes, true) && $depth === 0) {
|
||||
$page_icon = get_field('page_icon', $item->object_id) ?? null;
|
||||
$icon = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '<img class="page_icon" src="' . $page_icon['url'] . '" alt=""/>' : '';
|
||||
$output = '<button type="button" class="menu-item__submenu-toggle" aria-expanded="false" aria-controls="sub-menu-' . $item->ID . '">' . $icon . $item->title . '</button>';
|
||||
return $output;
|
||||
}
|
||||
// write_log($item->classes);
|
||||
if ($args->theme_location === "primary" && !in_array('menu-item-has-children', $item->classes, true)) {
|
||||
|
||||
|
||||
|
||||
if ($args->theme_location === "primary" && !in_array('menu-item-has-children', $item->classes, true) && $depth === 1) {
|
||||
$page_icon = get_field('page_icon', $item->object_id) ?? null;
|
||||
$icon = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '<img class="page_icon" src="' . $page_icon['url'] . '" alt=""/>' : '';
|
||||
$output = '<a href="' . $item->url . '">' . $icon . $item->title . '</a>';
|
||||
$icon_html = isset($page_icon) && is_array($page_icon) && !empty($page_icon['url']) ? '<img class="page_icon" src="' . $page_icon['url'] . '" alt=""/>' : '';
|
||||
|
||||
$page_subtitle = get_field('page_subtitle', $item->object_id) ?? '';
|
||||
$subtitle_html = '<span class="page_subtitle">' . $page_subtitle . '</span>';
|
||||
|
||||
if ($item->type === 'post_type_archive') {
|
||||
$icon_html = get_archive_page_icon_html($item->object);
|
||||
$subtitle_html = get_archive_page_subtitle_html($item->object);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$output = '<a href="' . $item->url . '">' . $icon_html . '<div class="menu-item__content-inner"><span class="menu-item__title">' . $item->title . '</span>' . $subtitle_html . '</div></a>';
|
||||
return $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
|
@ -69,7 +86,7 @@ function tailpress_nav_menu_add_submenu_class($classes, $args, $depth)
|
|||
add_filter('nav_menu_submenu_css_class', 'tailpress_nav_menu_add_submenu_class', 10, 3);
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
##### Inject ACF page_icon into submenu items
|
||||
##### Inject ACF page_icon and page_subtitle into submenu items
|
||||
------------------------------------------------------------------*/
|
||||
function carhop_add_submenu_item_icon($output, $item, $depth, $args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,12 +8,9 @@ function carhop_wrap_parent_menu_item_buttons($output, $item, $depth, $args)
|
|||
{
|
||||
if ($args->theme_location === "primary") {
|
||||
$page_icon = get_field('page_icon', $item->object_id) ?? null;
|
||||
// $test = get_field('page_icon', 729);
|
||||
// write_log($test);
|
||||
|
||||
if (isset($page_icon) && is_array($page_icon) && !empty($page_icon['url'])) {
|
||||
$icon = '<img class="page_icon" src="' . $page_icon['url'] . '" alt=""/>';
|
||||
// Insérer l'icône à l'intérieur du lien (seulement la première occurrence)
|
||||
$output = preg_replace('/>/', '>' . $icon, $output, 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,7 +33,7 @@ add_filter('walker_nav_menu_start_el', 'carhop_wrap_parent_menu_item_buttons', 1
|
|||
function carhop_add_page_icon_class($classes, $item)
|
||||
{
|
||||
$page_icon = get_field('page_icon', $item->object_id);
|
||||
if (isset($page_icon)) {
|
||||
if (isset($page_icon) || $item->type === 'post_type_archive') {
|
||||
$classes[] = 'has-page-icon';
|
||||
}
|
||||
return $classes;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user