altering menu links
I'm lost from the previous 4 hours looking for the right Drupal 6 code and/or how to implement it.
In short: I have a website. It has a menu. This menu is the Primary Links menu. I want to 'alter' each link that is displayed in this section to have tags enclosed around the link text. These span tags should be inside the tags.
Rather than this:
It should look like:
...and I'm using the following to output the menu:
<?php
print menu_tree($menu_name = 'primary-links');
?>I have checked out menu_tree, menu_tree_item API specifically (I assumed that's what I needed) but can't really get anything set in stone. I also took a look at hook_menu_link_alter, but I don't think that is going to do what I want to do.
I don't know now; I've read enough to be confused. I can't ever tell if I'm reading code for D4, D5, or D6 (Other than the 'posted' date)
If someone could point me in the right direction, that would be awesome!

D'oh!
Here's what I missed:
...
These span tags should be inside the
<a>tags....
...
Rather than this:
<li class="leaf"><a href="#" title="Test">Test</a></li>It should look like:
<li class="leaf"><a href="#" title="Test"><span>Test</span></a></li>...
Looks like you are trying to
You'll need to override the theme_menu_local_task function in your template.php. The following example should get your started.
/*** Returns the rendered HTML of the primary local tasks.
*/
function phptemplate_menu_local_task($mid, $active, $primary) {
if ($active) {
//DO SOMETHING TO THE ACTIVE MENU TASK
return '<li class="active">'. menu_item_link($mid) ."</li>\n";
}
else {
//DO SOMETHING TO THE MENU TASK
return '<li>'. menu_item_link($mid) ."</li>\n";
}
}
Inside the if/else is where you can do something to your menu items.
Heres two simple ways to
Heres two simple ways to achieve this:
http://agaricdesign.com/note/add-a-span-wrapper-inside-primary-and-secon...
Gives you the full rundown on how to add the span tags to primary and secondary links by modifying the theme_links function (they both use this function).
The other way is to use jQuery, you can add this to your scripts.js in your theme (add one if there isn't, Drupal will pick up the new file automatically when after you clear the theme registry).
// Wrap span tags around anchors in the primary menu.$(document).ready(function(){
$("#primary li a")
.wrapInner("<span>" + "</span>");
});
Where
$("#primary li a")matches your theme (so you might need to adjust it). Here I would be printing id="primary" either in the UL or in a wrapper div.Thanks so much for both of
Thanks so much for both of your replies! I'm going to see about implementing this stuff and report my hopeful success.
The jsQuery solution works
The jQuery solution works flawlessly, and it was very quick to implement. I'm going to try the other two solutions to see how they work. Thanks again both of you!