Add classes to these links I don't think this is hard at all but beeing a beginner at PHP and Drupal I need some help to do this.

I want to be able to add classes to my navigation elements that are outputted with this code:

function mytheme_menu_link__menu_block__1($variables) { 

$element = $variables['element'];

$sub_menu = '';

if ($element['#localized_options']['attributes']['title'] != 'misc' &amp;&amp; $element['#localized_options']['attributes']['title'] != 'something') {

    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }

    if ($element['#original_link']['in_active_trail'] == 0) {
        $output = ''.$element['#title'].'';
    }
    else {
        $output = ''.$element['#title'].'';
    }

    $link = l($output, $element['#href'], array('html' =&gt; TRUE));

    return $link;
}
else {
    return '';
}
}


If the menu item is active, it should have class X, otherwise class Y.
Could someone explain how I add this?

------------------------- Correct Answer -------------------------------

Here is the correct code that longboardnode helped me come up with.

function mytheme_menu_link__menu_block__1($variables) { 

$element = $variables['element'];
$sub_menu = '';

if ($element['#localized_options']['attributes']['title'] != 'misc' &amp;&amp; $element['#localized_options']['attributes']['title'] != 'something') {

    if ($element['#below']) {
        $sub_menu = drupal_render($element['#below']);
    }

    if ($element['#original_link']['in_active_trail'] == 0) {
        $output = $element['#title'];
        $class = 'activeClass';

    }
    else {
        $output = $element['#title'];
        $class = 'otherClass';

    }

    $link = l($output, $element['#href'], array('attributes' =&gt; array('class' =&gt; array($class)), 'html' =&gt; TRUE));

    return $link;
}
else {
    return '';
}


}
I hope I understand your question. If you want to add class to l(), then it must be an array, so your "$link=..." line would read

$link = l($output, $element['#href'], array('attributes' =&gt; array('class' =&gt; array('YOUR_CLASS_NAME')), 'html' =&gt; TRUE));


You can also read more and see other examples in Drupal's l() documentation

Hope this helps.