Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking for a way to include a user managable title in a menu. Ideally, it will take the place of the first <li> object in the output.

Any ideas?


Edit Clarification

I am looking for a way to add a header to a menu list, defined by the given name of the menu in the admin panel.

So, the code should look a little like this:

<ul>
  <li class="title"> Menu Name</li>
  <li><a href=#>Link</a></li>
  <li><a href=#>Link</a></li>
  <li><a href=#>Link</a></li>
  <li><a href=#>Link</a></li>
</ul>

Edit Further Development

I have a code block for extracting the name of a menu, based on it's location in a theme, but I can't quite get the HTML layout I want (i.e. add the title to the first <li>).

function mf_get_menu_name($location){
    if(!has_nav_menu($location)) return false;
    $menus = get_nav_menu_locations();
    $menu_title = wp_get_nav_menu_object($menus[$location])->name;
    return $menu_title;
}
share|improve this question
    
care to explain a bit more? –  Bainternet Jul 19 '11 at 11:01
    
Added clarification and details of where I am with the problem. –  Mild Fuzz Jul 19 '11 at 15:39
add comment

1 Answer

Are you looking to put a title on the nav links? That is built into the Menu feature in Wordpress.

Wordpress Title Menu

But this applies to the tag and not the <li> as you specified. You can, however, apply a class to the <li> by clicking the "Screen Options" link while in the Menu Admin page. Then, find the "CSS Class" checkbox under "Show advanced menu properties".

Finally, you could give your links the desired title and then apply the following jQuery to apply the title to the <li> and remove it from the <a>.

$(function() {

    $('ul li').each(function() {

        var linkTitle = $(this).find('a').attr('title'); //get the link title
        $(this).attr('title', linkTitle); //apply the title to the li

        $(this).find('a').removeAttr('title');
    });

});

JSFiddle example: http://jsfiddle.net/tmort/E5VzC/3/

share|improve this answer
    
Sorry, not really what I meant, I have explained further in the question. –  Mild Fuzz Jul 19 '11 at 19:23
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.