Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

Boris Kamp
Boris Kamp
16,660 Points

edit wp_nav_menu output

Hi guys!

I want to edit the output of my menu. I've set it up this way:

$args = array(
              'menu'        => 'header-menu',
              'menu_class'  => 'nav navbar-nav',
              'container'   => 'false',
              //'link_before' => '<i class="fa fa-home"></i>',
);
wp_nav_menu( $args );

note the commented out link before, I want that to only to display in the first <li> now I read somewhere I can edit the first <li> class by doing so:

// add home i to first list item in menu
    function first_li_menu_before($items) {
        $items[1]->classes[] = 'first';
        return $items;
    }
    add_filter('wp_nav_menu_objects', 'first_li_menu_before');

Now I thought I could use $items[1]->link_before[] = '<i class="fa fa-home"></i>'; to prepend the glyphicon, but it does not work. I have found no way to debug $items so I dont know how the object is constructed so I can target it right. any ideas?

Thanks!