0

I would like to place the search bar in the main menu on the right. I have seen several people on the net asking for this but never encountered some information I could actually use. I use Drupal 7 and the "Responsive Blog" by Devsaran.

As far as I understand the way to go is inserting some php into the main menu code in the main-menu part in page.tpl. This is what it looks like but I am struggeling with the exact to dos now...

<nav id="navigation" role="navigation">
  <div id="main-menu">
    <?php 
      if (module_exists('i18n_menu')) {
        $main_menu_tree = i18n_menu_translated_tree(variable_get('menu_main_links_source', 'main-menu'));
      } else {
        $main_menu_tree = menu_tree(variable_get('menu_main_links_source', 'main-menu'));
      }
      print drupal_render($main_menu_tree);
    ?>
  </div>
</nav>

1 Answer 1

4

Here is one approach:

  1. Start by adding a new region to the theme's .info file:

    regions[navigation] = Navigation

  2. Next, render the region. Put the code below in page.tpl.php either just before or just after the </div> in your code above. You may need to experiment a little.

    <?php print render($page['navigation']); ?>

  3. Clear your cache so your site knows that the new region exists.

  4. Next, in Admin -> Structure -> Blocks, place the Search block in the Navigation region.

  5. Finally, style the search form so it looks the way you want.

1
  • 1
    Remark for other readers: I had to insert it between <nav> and <div>: <nav id="navigation" role="navigation"> <?php print render($page['navigation']); ?> <div id="main-menu">
    – Largo
    Dec 16, 2014 at 14:49

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.