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 trial

WordPress

Conditional 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
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi 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/

Hi Zac Gordon

Legend thanks for that. Hmmm did not put my code in correctly in the post DOH!!!

But thanks anyway.

G

Although 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