How do I remove the active class in the main menu?

One item in the menu has sub-items that point to the same page (just with different arguments) ex:

Products – List item 1 products?pid=1 – List item 2 products?pid=2 – List item 3 products?pid=3

Drupal assigns the “active” class in the

  • and tag of the menu items since all the items have the same page url (products)

    I’m overwriting the menu_link function in template.php to remove the active class but the class remains in the tag

    function mytheme_menu_link(array $variables) {   $element = $variables['element'];   $sub_menu = '';    if ($element['#below']) {      if (strtolower($element['#title']) == 'Products') {        if (isset($_GET['pid'])) {         $currID = $_GET['pid'];          foreach ($element['#below'] as $Taxonomy) {            if ($currTaxonomyID != $Taxonomy['#localized_options']['query']['pid']) {             $mlid = $Taxonomy['#original_link']['mlid'];             $key = array_search('active', $Taxonomy['#attributes']['class'], TRUE);                         if ($key) {               unset($element['#below'][$mlid]['#attributes']['class'][$key]);               $element['#below'][$mlid]['#localized_options']['attributes']['class'][$key] = '';             }             // remove active-trail class             $key = array_search('active-trail', $Taxonomy['#attributes']['class'], TRUE);                         if ($key) {               $element['#below'][$mlid]['#attributes']['class'][$key] = '';                           }           }                   }       }           }     $sub_menu = drupal_render($element['#below']);            }   $output = l($element['#title'], $element['#href'], $element['#localized_options']);     return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>n"; } 

    Final Result:

    <ul class="menu nav">    <li class="first leaf menu-mlid-44253">       <a href="/products?pid=1" title="Best Practices" class="active">Best Practices</a>     </li>     <li class="leaf menu-mlid-44254">       <a href="/products?pid=2" title="Checklists" class=" active">Checklists</a>     </li> .... 

    How can I remove the class “active” from the tag?

    My menu Structure:

    -Clients -Products   -prod1 (url:\products?pid=1)   -prod2 (url:\products?pid=2)   -prod3 (url:\products?pid=3)   -prod4 (url:\products?pid=4) -About 
  • This article was republished from its original source.
    Call Us: 1(800)730-2416

    Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

    FREE Drupal SEO Audit

    Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

    Powered by

    How do I remove the active class in the main menu?

    On-Site Drupal SEO Master Setup

    We make sure your site is 100% optimized (and stays that way) for the best SEO results.

    With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

    This service includes:

    • Pathauto install and configuration for SEO-friendly URLs.
    • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
    • Install and fix all issues on the SEO checklist module.
    • Install and configure XML sitemap module and submit sitemaps.
    • Install and configure Google Analytics Module.
    • Install and configure Yoast.
    • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
    • Install and configure Schema.org Metatag.
    • Configure robots.txt.
    • Google Search Console setup snd configuration.
    • Find & Fix H1 tags.
    • Find and fix duplicate/missing meta descriptions.
    • Find and fix duplicate title tags.
    • Improve title, meta tags, and site descriptions.
    • Optimize images for better search engine optimization. Automate where possible.
    • Find and fix the missing alt and title tag for all images. Automate where possible.
    • The project takes 1 week to complete.