Making wordpress parent navigation items unclickable with jquery

I’m developing a new site that has a navigation that is built dynamically via wordpress’ wp_list_pages function

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

Navigation items that have submenus (css dropdowns) are still clickable, but for this website they have no content. I wanted a way to make those items unclickable. I was unable to find any way with wordpress’ api, but I did find a way with jquery.

$('#navigation_ul > li > a').filter(
    function() {
        return $(this).siblings().length > 0
    }
).attr( 'href', '#' )
 .attr( 'onClick', 'return false' );

All navigation links that have submenus will have their href to ‘#’, and onClick set to ‘return false’.

Add a response

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">