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:

<li><?php if ( is_home() ) { ?> class="current_page_item"<? } ?><a href="<?php get_option('home'); ?>">Home</a></li>
<?php wp_list_pages('title_li='); ?>

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.

8 thoughts on “The easiest way to display ‘Home’ as a navigation link, Period.

  1. How about just using:


    That works just the same!!! No reason to have all that code above! WP adds the current page item by default. x

  2. 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.

  3. I would prefer myself ( keeping the above comment in mind also )
    [?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=’); ?]

    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.

  4. the 2 blocks in [?php .. ?] tags are each 1 line. And all tags above are changed to square brackets for anyone who cares.

Comments are closed.