Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGraham Davidson
Courses Plus Student 14,966 PointsConditional Tags and Menu Selection
Morning all looking for a little Wordpress guidance please.
I am trying to make menu items have an id of selected if you are on the relevant page.
I am using
<li <?php if(is_home()){echo 'id="selected"'}?>><a href="<?php bloginfo('url');?>">Home</a></li>
As an example but all this is doing is crashing the site. Can anyone help please
G
2 Answers
Zac Gordon
Treehouse Guest TeacherHi Graham Davidson! WordPress has a built in active class that it applies to menus. It may be easier to change your styles to match it's markup, although if you really get into the menu template tag you can change the class name.
Check out this real simple article from WPMU: http://wpmu.org/how-to-highlight-the-current-page-when-using-wordpress-navigation-menus/
Graham Davidson
Courses Plus Student 14,966 PointsAlthough school boy error I am not using a WP menu its just a hard coded <ul>
Is it just as easy to change it to a WP menu to get around this
Graham Davidson
Courses Plus Student 14,966 PointsGraham Davidson
Courses Plus Student 14,966 PointsHi Zac Gordon
Legend thanks for that. Hmmm did not put my code in correctly in the post DOH!!!
But thanks anyway.
G