Support » Fixing WordPress » How to avoid clicking of main menu items?

  • Resolved tanver


    I am using WordPress 3.1.2 without custom menus [did try but with out any success].
    I want to disable [click on] a menu item in the menu-bar if it has a sub-menu item associated with it. I will really appreciate if someone can help me achieve this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • It is easy to make a non-clickable item using custom menus, but I do not know an easy way to do it otherwise.

    In a custom menu, create a ‘Custom Links’ entry using a single pound sign (#) for the URL and whatever you want for the Label.

    Maybe someone else has a way to do it without a custom menu.

    Just for knowledge sharing may be it proves helpful for someone else I did this by adding a JQuery Script

    <script type="text/javascript">
    jQuery('.page-item-7 a:first').attr('href', '#');

    Obviously by adding reference to all the menu-items [pages in my case], I did find this code from somewhere but don’t remember now. I know it can be improved to dynamically skipping the menu items having some ‘chile nodes’ but with my limited knowledge of JS I could not accomplish the same and would appreciate if someone can go a step even further to achieve this.
    I am using a child theme of Twenteyten 1.2 [the version build with WP 3.1]

    Hi there

    Where does that piece of code go?

    I have a custom menu, and when a user hovers over certain menu items, there is a list of sub menus. I want to ensure that they can click on menu items with no sub menus but force them to click on a sub menu item where present.

    Will the code you provided do that?
    To see what I mean ->

    Thank you

    Yes, the code will work and server your purpose you need to put this code in the head section [header.php]. You need to replace .page-item-7 for all the top level items you don’t need to be click-able [Not really, will reference to current page].

    mmm…think the theme i am using is using something different or something…no idea what the hell is going on 😐

    Sure ill figure something out soon…

    This is the coding for the menu:

    <div id="sf-menu" class="jqueryslidemenu">
            	<div class="sidebar_divider"></div>
    	$primary = '';
    	$primary = wp_nav_menu( array( 'container' => 'ul', 'theme_location' => 'primary-menu', 'fallback_cb' => '', 'menu_class' => 'sf-menu', 'echo' => false, 'link_before' => '<strong>', 'link_after' => '</strong><span>&nbsp;</span>' ) );
    	$primary = preg_replace('/(<a[^>]+>)([^\/]+)\/([^<]+)<\/strong><span>&nbsp;<\/span>(<\/a>)/','$1$2</strong><span>$3&nbsp;</span>$4', $primary);
    	if($primary <> "") {
    	} else { ?>
    		<ul id="menu-navigation" class="sf-menu">
    			<li><a href="<?php bloginfo("home"); ?>" title="<?php echo wp_specialchars( get_bloginfo('name'), 1 ) ?>" rel="home"><strong>Home </strong><span> homepage&nbsp;</span></a></li>
    			<?php foreach ( (get_pages('sort_column=menu_order') ) as $page ) { if ( $page->post_parent == '0' ) { ?>
    				<a href="<?php echo get_page_link($page->ID); ?>"><strong><?php echo $page->post_title; ?> </strong><span> <?php echo get_post_meta($page->ID, "subtitle", true); ?>&nbsp;</span></a>
    				$child_pages = get_pages('child_of='.$page->ID);
    				if (get_page_children($page->ID, $child_pages) ) { ?>
    					<ul><?php wp_list_pages('title_li=&child_of=' . $page->ID ); ?></ul>
    				<?php } ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to avoid clicking of main menu items?’ is closed to new replies.