Disable click on WordPress parent menu with children

Tags: , , ,

I’ve got a few sites where the client has requested that main menu items that have sub-menu items not be clickable, but just be a placeholder for the sub menu items themselves.

This comes in handy, specifically, when you have drop down menus (using SuperFish, for example) — Safari on iOS handles SuperFish pretty well – the first tap drops down the menu, and the second tap will actually take you to that page, but what if you don’t want the first level to take you anywhere?

Adding the following to your theme’s functions.php file will do just that.

function jqueryscript_in_head(){ ?>
<script type="text/javascript">
var $j = jQuery.noConflict();
$j(document).ready(function () {
$j("li:has(ul)").children("a").click(function () {
    return false;
});  });
</script>
<?php }
add_action('wp_head', 'jqueryscript_in_head');

 

Top