I recently wrote a theme function to add a class to my main links, which works great. Then I wrote some css classes to create these links with custom background images. Excellent. Now there is a problem, the link text for the main links is displayed. This is usually not a problem, as I would just wrap it in a regular βhideβ class. For instance:
<span class="hide"><a href="#">Link Text</a></span>
So my question is: how can I scroll through primary links and wrap text w / a <span> , as my example? Here is my theme function that I used to add my classes.
function zkc_preprocess_page(&$vars, $hook) { // Make a shortcut for the primary links variables $primary_links = $vars['primary_links']; // Loop thru the menu, adding a new class for CSS selectors $i = 1; foreach ($primary_links as $link => $attributes){ // Append the new class to existing classes for each menu item $class = $attributes['attributes']['class'] . " item-$i"; // Add revised classes back to the primary links temp variable $primary_links[$link]['$attributes']['class'] = $class; $i++; } // end the foreach loop // reset the variable to contain the new markup $vars['primary_links'] = $primary_links; }
source share