title: Drupal: Changing the link of menu children to anchors
body: <p>My goal is to modify the output of a menu so that the submenu links are anchors of the parent item:</p>
  
  <pre><code>&lt;ul class="menu"&gt;
    &lt;li&gt;
      &lt;a href="page1"&gt;Page 1&lt;/a&gt;
      &lt;ul class="submenu"&gt;
        &lt;li&gt;
          &lt;a href="page1#section"&gt;Section&lt;/a&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Because the Drupal GUI doesn't allow anchors in menu items, I need to modify the <code>theme_link()</code> function to change all children:</p>
  
  <pre><code>function MYTHEME_menu_link__menu_block__main_menu(array $variables) {
    $element = $variables['element'];
    $sub_menu = '';
  
    if ($element['#below']) {
  
      foreach($element['#below'] as $child) {
        $child['#href'] = str_replace(' ', '-', strtolower(render($child['#title'])));
      }
  
      $sub_menu = drupal_render($element['#below']);
    }
  
    $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    return '&lt;li' . drupal_attributes($element['#attributes']) . '&gt;' . $output . $sub_menu . "&lt;/li&gt;\n";
  
  }
  </code></pre>
  
  <p>But there are two problems, which are a result of my lack of experience with Drupal functions:</p>
  
  <ol>
  <li>The changed <code>href</code> is not being passed to the rendered HTMl.</li>
  <li>I receive this error for line 8: <code>Warning: Cannot use a scalar value
  as an array</code>.</li>
  </ol>
  
  <p>What do I need to correct this error, and how can I pass the new <code>href</code> to the menu-children's output link?</p>
  
  <p>EDIT: I should add that I’m using Entity Reference to pull nodes into one super page, and there are three super pages on the site. So using a single-page solution will not work for me.</p>