Skip to content

Instantly share code, notes, and snippets.

@bdnorris
Created July 21, 2023 16:08
Show Gist options
  • Save bdnorris/debade4a43d600c7f03c3c40c1347057 to your computer and use it in GitHub Desktop.
Save bdnorris/debade4a43d600c7f03c3c40c1347057 to your computer and use it in GitHub Desktop.
WordPress filter to replace top level menu items with buttons
<?php
function edit_menu_item($item_output, $item) {
if ( in_array('menu-item-has-children', $item->classes) ) {
return '<button type="button" aria-expanded="false" id="' . $item->title . '-' . $item->ID . '">'.$item->title.'</button>';
}
return $item_output;
}
add_filter('walker_nav_menu_start_el','edit_menu_item', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment