Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 686489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:01:47+00:00 2026-05-14T02:01:47+00:00

I recently wrote a theme function to add a class to my primary links

  • 0

I recently wrote a theme function to add a class to my primary links that works great. I then wrote some css classes to style these links with custom background images. Worked out great. Now comes the problem, the link text for the primary links still is displayed. Normally this isn’t a problem as I would just wrap the in a with a custom “hide” class. For example:

<span class="hide"><a href="#">Link Text</a></span>

So my question is how can I loop through the primary links and wrap the text w/ a <span> like my example? Here’s 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;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:01:47+00:00Added an answer on May 14, 2026 at 2:01 am

    Is jQuery an option?

    Try something like this:

    $(document).ready(function(){
      $('#primary li a')
      .wrapInner('<span class="hide">' + '</span>');
    });
    

    EDIT:

    Or if you want to go Drupal, put this guy in your foreach loop:

    $link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm refactoring some code that a friend wrote and recently stumbled across this function:
I recently wrote some data access methods (plain old Java) that use immutable objects
So I recently wrote a java class that extends exception and used an instance
I recently wrote some javascript code that filled a drop down list based on
I wrote a theme for Google+. It injects CSS/Javascript to replace some colors, background
Hey there, I recently wrote some Jquery to make all links external to a
I recently wrote code that didnt work as i would expect, it was: message
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Recently a co-worker of mine wrote in some code to catch a null pointer
I wrote a small jQuery application recently to practise the language and got some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.