The easiest way to display ‘Home’ as a navigation link, Period.
Here is the easiest way to display a homepage link in the navigation bar of your WordPress site. I can guarantee that you won’t find an easier way out there.
The code:
<ul>
<li<?php if ( is_home() ) { ?> class="current_page_item"<? } ?>><a href="<?php get_option('home'); ?>">Home</a></li>
<?php wp_list_pages('title_li='); ?>
</ul>
It’s pretty obvious how this code works. If the current page is the blog’s homepage, then it’ll add a special class to the list item to mark it as the current page. If it isn’t, the navigation button displays normally.
That’s it. No extra pages, no special configuration. The easiest way to display ‘Home‘ as a navigation link, period.






Pasquale
Posted on January 31st, 2008 at 3:58 am
You could always be an idiot and hardcode it.:P
dRiZ
Posted on January 31st, 2008 at 11:17 am
How about just using:
[code][/code]
That works just the same!!! No reason to have all that code above! WP adds the current page item by default. x
Simon
Posted on January 31st, 2008 at 4:41 pm
I think there’s a slight typo in your code. The Span tag is breaking inside the li tag. I think you need to close the li tag before starting the span tag. Of course, you could get rid of the span tag completely, it doesn’t seem to be doing anything.
Also, from a usability point of view, it’s always wise to not link to the page the user is currently on.
Abba Bryant
Posted on January 31st, 2008 at 9:34 pm
I would prefer myself ( keeping the above comment in mind also )
[ul]
[?php echo ( is_home( ) ) ? "[li class='current_page_item' ]Home[/li ]” : “[li][a href='{get_option(home)}']Home[/a][/li]“; ?]
[?php wp_list_pages('title_li='); ?]
[/ul]
I hope this comes through alright. If it doesn’t, this is a perfect case for a ternary and the poster above is right, the home page should NOT have a link to the home page. A text representation is better in this case than a link.
Abba Bryant
Posted on January 31st, 2008 at 9:34 pm
the 2 blocks in [?php .. ?] tags are each 1 line. And all tags above are changed to square brackets for anyone who cares.
Michael Castilla
Posted on February 1st, 2008 at 12:29 am
@Simon: Thanks, should be fixed now.
@Abba & Simon: How come? Why shouldn’t there be a link on the ‘home’ text?
Tibor
Posted on February 2nd, 2008 at 2:12 am
@Simon: I think Abba & Simon mean that it should not be a link when it is the current page; something I actually agree with.
Tibor
Posted on February 4th, 2008 at 12:17 pm
I meant @Michael ofcourse..