To add an empty menu link, you need to add a menu item with # as URL ( Custom Links ) to add an empty menu link.
Then you can simply open functions.php file in your parent or child theme folder. Then add the below code at the end of the file.
// add javascript:void(0) to menu items with # url
add_filter('walker_nav_menu_start_el', 'mswa_replace_hash', 999);
function mswa_replace_hash($menu_item) {
if (strpos($menu_item, 'href="#"') !== false) {
$menu_item = str_replace('href="#"', 'href="javascript:void(0);"', $menu_item);
}
return $menu_item;
}
You can find a detailed explanation of this code in our blog post about adding menu without link