I need to add some custom markup inside the first list-item of the main-menu as you can see here:

<div id="block-system-main-menu">
    <div class="block-inner clearfix">
        <div class="content clearfix">
            <ul class="menu">
                <li class="first leaf"><a href="/de/t1">Item 1</a>
                    <div class="my-custom-markup>
                <li class="leaf"><a href="/de/t2">Item 2</a></li>
                <li class="last leaf"><a href="/de/t3">Item 2</a></li>

With the following code, I can insert the markup:

function mytheme_preprocess_menu_link(&$variables) {
  $variables['element']['#below']['#markup'] = ' <div class="my-custom-markup">...</div>';

But this code adds the markup to every list-item, not just the first one. Do I use the appropriate function and how can I add the markup only at the first item of main menu?

1 Answer 1


I managed to apply the code only to the item in the main-menu by introducing a condition of menu-name and #href:

function mymodule_preprocess_menu_link(&$vars) {
  $element = &$vars['element'];
  $my_view = views_embed_view('view_name', 'display_id');
  if(strpos($element['#href'], 'home') !== false && $element['#original_link']['menu_name'] == 'main-menu')
    $element['#below']['#markup'] = $my_view;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.