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 Sub Menus

I recently did the Wordpress portfolio project on here and we used the following code to strip the menu li tags: <?php $args = array( 'menu' => 'main-menu', 'echo' => false ); echo strip_tags(wp_nav_menu( $args ), '<a>'); ?>

Which produced an output like this:

<ul> <a href="#">Menu 1</a> <a href="#">Menu 1</a> <a href="#">Menu 1</a> </ul>

The problem is when I add in sub-menu items in wordpress the output now looks like this:

<ul> <a href="#">Menu 1</a> <a href="#">Sub-Menu 1</a> <a href="#">Sub-Menu 2</a> <a href="#">Menu 1</a> <a href="#">Menu 1</a> </ul>

My problem is that I cannot figure out how to select the sub menu items in CSS to create a drop down menu. Normally I would use selectors to target the ul's that are within line items and create the drop down by hiding these and showing them on hover.

If anyone can help me figure how to create a drop down with this stripped menu I would be very appreciative!

Chris Dziewa
Chris Dziewa
17,781 Points

I'm trying to figure this out too. I believe it has to do with extending the walker class in wordpress but the codex doesn't have good documentation about it. If I figure it out, I'll let you know.