0
votes

In my php generated nav-menu I'd like to make parent items unclickable and not related to a page. I just want them to reveal children when hover.

PHP code generating the nav-menu:

<?php wp_list_pages('sort_column=menu_order&title_li='); ?>

I'd need to remove the href link in any element that has "page_item_has_children" as class.

Can't use the "custum link" method because since my theme is made from scratch I don't have access to that wp setting.

1

1 Answers

0
votes

Just save menu code in variable and remove all links through preg_replace.

$menu = wp_list_pages( 'echo=0&sort_column=menu_order&title_li=' );
$finalMenu = preg_replace('/(page_item_has_children.*?)<a href=\".*?\">(.*?)<\/a>/', '\\1\\2', $menu);
echo $finalMenu;