WordPress.org

Ready to get started?Download WordPress

Forums

Display Title Attribute in Menu (3 posts)

  1. ghostpool
    Member
    Posted 4 years ago #

    I'm using the new menu system in WordPress 3.0 and wondering if it's possible to display the title attribute ($menu_item->attr_title) which you can specify for a page or category within the menu itself. I'm using something like this, but the title will not display unfortunately:

    <?php wp_nav_menu('sort_column=menu_order&container_class=&menu=Header Navigation&link_after=<br />'.$menu_item->attr_title); ?>
  2. youtag
    Member
    Posted 3 years ago #

    hello, i know it is an old question, but i thought id share my solution. perhaps it's useful for someone else.

    add this to your functions.php

    add_filter('walker_nav_menu_start_el', 'description_in_nav_el', 10, 4);
    function description_in_nav_el($item_output, $item, $depth, $args)
    {
    	return preg_replace('/(<a.*?>[^<]*?)</', '$1' . "<em>{$item->attr_title}</em><", $item_output);
    }
  3. advinci
    Member
    Posted 3 years ago #

    Thanks youtag. This was indeed helpful.

Topic Closed

This topic has been closed to new replies.

About this Topic