I need to add a checkbox for menu items from Appearance -> Menus -> Menu structure -> Item
. If the checkbox is checked, the target="_blank"
attribute is added to the a
tag.
I want something like this screenshot:
Can you tell me if this is possible? And can you help me with this?
Thanks!
EDIT:
This is a rendering of the menu in my case:
<?php wp_nav_menu([
'theme_location' => 'primary',
'container' => '',
'walker' => new description_walker(),
]); ?>
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth = 0, $args = null, $id = 0)
{
$title = trim($item->title);
$classes = (!empty($item->classes)) ? implode(" ", $item->classes) : '';
$button = (!empty($item->classes) && in_array('menu-item-has-children',
$item->classes)) ? '<span class="button-show">+</span>' : '';
$output .= "<li class='" . $classes . "'>";
$output .= '<a href="' . $item->url . '">';
$output .= $title;
$output .= '</a>';
$output .= $button;
}
}