How to Remove Links from WordPress Menu Items


It’s a divisive question – should the page at the top of a sub-menu be a clickable link or not? I guess the answer depends on your website, and ultimately whether you are adding valuable content by creating a full page or whether you’re doing it for the sake of it. Either way, there will be situations in which you would like to have a sub-menu on your website but don’t want the top link to be clickable. There are several ways to handle this, but one really simple way is to create a custom link within the WordPress menu:

  1. Go to Appearance -> Menus
  2. Click ‘Custom Links’
  3. For the URL, enter a hash symbol (#)
  4. Enter your title for the Link Text
  5. Click ‘Add to Menu’
  6. Arrange your sub-menu as appropriate

The only problem with this is that your top menu item, which the sub-menu sits under, looks and behaves like a link, despite the fact that it’s not clickable. However, there’s a simple solution to this. If you have access to your functions.php file then you can add the following code to it:


function wws_rg_remove_hash_links( $menu ) {
return str_replace( '<a href="#">', '<a>', $menu );
}

add_filter( 'wp_nav_menu_items', 'wws_rg_remove_hash_links' );

If you don’t have access to the functions.php file, or don’t feel comfortable doing this, don’t worry – you can just install our plugin to do it for you. You can download the plugin from the WordPress Plugin Directory, or just install it directly from WordPress by going to Plugins -> Add New. Once you have installed it, just activate and you’re done!