WordPress Selected Nav Links

This is a post to share with the many people out there that probably have the same problem that I had today. So instead of you spending all your time trying to figure out this problem I am going to share with you my solution. Well to start off you need to know my problem I was creating a theme today and needed the nav links to be in a selected state when you were on that specific page. I had no clue how to do this in WordPress so I spent about 4 hours of my day looking up this problem. After that time I found the answer to my problem. The answer I am going to be showing is for the traditional header.php file that holds most everyone’s nav bar or your header links. All you have to do to have your page links to show in the nav and get them to be at a selected state as followed:

This part is for your Home Page so if you don’t want your home page than just don’t add this into your code.

<li id=”home” <?php if(is_home()) { ?> class=”selector” <?php } ?> ><a href=”<?php echo get_settings(‘home’); ?>”>Home<?php echo $langblog;?></a></li>

This is for the other pages that you have in WordPress.

<?php wp_list_pages(‘title_li=’);?>

Now all you have to do to get these links to be in a selected stage is add a little code to your css code which is as followed.

This is for home.

Your ID like #nav Then li.selector a {color: ###;}

This is for other pages.

Your ID like #nav Then li.current_page_item a {color: ###;}

Now some people like to have there categories do this same thing. Well all you have to do for that is change wp_list_pages to wp_list_categories so that it can list the categories. Then just change your css code from li.current_page_item to li.current-cat and you are finished.

If you have any questions about this just leave a comment of go to my Contact Page for my email.

Shane Strong
Chosen Development

Popularity: 3% [?]

(7) Responses to “WordPress Selected Nav Links”

  1. zerodx Says:
    -

    thank you so much!!!!!!!!!!!!!!!!!!!!!!

  2. Britney Kate Says:
    -

    Thanks for this Great Information :)
    Very usefull information to all of us, especially i like your blog design, Very Attractive Design & Try to Add some Social Media Widget This will increase your blog visibility.
    I will bookmark this url to my facebook Account, will visit again.

    Britney

  3. Dave Says:
    -

    Hey, would you like to submit comments and backlinks to millions of blogs automatically? Blog Comment Poster will do it for you. Blog Comment Poster will increase your traffic, backlinks and earnings dramatically! Sounds cool? Yes, it is cool! It’s the best automated comments posting tool on the Internet with many advanced features. Check it out!

  4. Stan Says:
    -

    Yep, took me 4 hours before I found your article about this as well. Thanks for posting the solution. Now time to sleep relieved.

  5. buy bedding Says:
    -

    I am amazed with it. It is a good thing for my research. Thanks. ^_^

  6. budget car insurance Says:
    -

    Great article! I’m loving your website;

  7. Bookmark Links Says:
    -

    Hi there, I found your blog via Google while searching for bookmark links and your post regarding WordPress Selected Nav Links looks very interesting for me. Keep up the good work.

Leave a Reply

Your Avatar
Your Name
September 6th, 2010