Remove Drupals .menu-position-link menu items (Menu Position module)

Menu Position is a great Drupal Module to get the .active-trail class in the menu, without adding eg. all news article nodes to the it.

The only problem is a „placeholder“ link created instead, class: „.menu-position-link“. It seems this is technically necessary.

Here is a little jQuery function to remove the element itself, the container menu (if its the only item) and fix the causing classes. You may have to alter it a bit.

Remove the console.logs before using it on productive environment!

$('.menu', context).children('').each(function() {
  var menuChildCount = $(this).children('.menu').children('li').length;
  var $menuPosLinkParent = $(this).find('.menu-position-link').parent();
  if ($menuPosLinkParent.length) {
    console.log('Found one - childcount:' + menuChildCount);
    if (($menuPosLinkParent).hasClass('last')) {
      console.log('Its the last item.');
      // If its the last link move class .last to the menu item before 
    if (menuChildCount === 1) {
      console.log('Its the only item.');
      // If menu position link is the only menu-item, remove parent trails .expanded 
      console.log('Removed it.');
    } else {
      console.log('Removed it.');

    Schreibe einen Kommentar

    Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

    Der Zeitraum für die reCAPTCHA-Überprüfung ist abgelaufen. Bitte laden Sie die Seite neu.