I attempted to create a filter for wp_nav_menu_objects that checked if the menu item was a dropdown and inserted another menu item. It didn’t work as expected and instead added several empty menu items.
function add_split_to_nav($items, $args) {
foreach ($items as $item) {
foreach($item->classes as $key=>$class) {
if ($class == “menu-item-has-children”) {
$link_args = (object) array (
‘title’ => ‘TEST’,
‘menu_item_parent’ => 0
);
$link = new WP_Post($link_args);
array_splice($items, $key, 0, $link);
}
}
}
return $items;
}
add_filter(‘wp_nav_menu_objects’, ‘add_split_to_nav’, 10, 2);
I think the link in your OP may have a typo, but if you’re talking about http://fontawesome.io/ then why not just add your custom link in the Menus admin interface and apply some CSS classes right there? Maybe I don’t understand what you’re trying to accomplish…
Does your code work in one of the default themes or did you copy it from a demo on a blog? If not, then this isn’t really a Roots and would be better served on WordPress answers, Stack Overflow or the blog (if applicable).
Generally speaking, accessing the WordPress classes directly instead of using helper functions is a bad idea.
I feel like an idiot. I’ve spend hours trying to figure out a PHP hack. Adding the extra menu item from the admin interface worked exactly how I wanted it to.
Great! I’ve definitely been in a similar position. Sometimes when you’re so focused on a project you just need a fresh set of eyes to de-clutter what you’re chasing. Glad you got it sorted