FEATURE Ajout d'icônes de page aux éléments de menu avec sous-menu
This commit is contained in:
parent
12e787c63e
commit
79cf48fa18
|
|
@ -7,11 +7,21 @@
|
|||
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)) {
|
||||
$output = '<button type="button" class="menu-item__submenu-toggle" aria-expanded="false" aria-controls="sub-menu-' . $item->ID . '">' . $item->title . '</button>';
|
||||
}
|
||||
if ($args->theme_location === "primary" && in_array('menu-item-has-children', $item->classes, true)) {
|
||||
$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>';
|
||||
}
|
||||
// write_log($item->classes);
|
||||
if ($args->theme_location === "primary" && !in_array('menu-item-has-children', $item->classes, true)) {
|
||||
|
||||
$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>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
add_filter('walker_nav_menu_start_el', 'wrap_parent_menu_item_buttons', 10, 4);
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@
|
|||
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);
|
||||
$page_icon = get_field('page_icon', $item->object_id) ?? null;
|
||||
// $test = get_field('page_icon', 729);
|
||||
// write_log($test);
|
||||
|
||||
if (isset($page_icon)) {
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user