X

How to Highlight the Current Page in WordPress Navigation Menu

Snippets by IsItWP

Do you want to highlight the current page in navigation or sidebar menu? Highlighting the current page makes navigation easier.

WordPress menu functions (wp_nav_menu, wp_list_pages) automatically add current_page_item class to li containing the active link. So all we have to do is use the same class to highlight the current page.

Instructions:

All you have to do is add this code to your theme’s style.css file:

/* Highlight using list element */
li.current_page_item{
	background:#999;
	color:#fff;
}

/* Highlight using link element */
li.current_page_item a{
	text-decoration:underline;
	background:#666;
}

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly copy / paste code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: Best WordPress Page Builders (Compared).

[code]/* Highlight using list element */ li.current_page_item{ background:#999; color:#fff; } /* Highlight using link element */ li.current_page_item a{ text-decoration:underline; background:#666; }[/code]

Comments   Leave a Reply

  1. where do i find the “theme’s style.css file” on the wordpress free version?

  2. Thank you. I have looked in a few places, but your solution worked. I really appreciate it!

    1. Hey Robert, glad our solution worked for you.

      Please follow us on Facebook and Twitter for more interesting guides. 🙂

  3. Work’s fine thanks !

  4. This code works if menu has one tear. Otherwise it highlights first level link and all sub categories in it.
    For example you would be at “home>about>news” and it would highlight all “home” categories instead of just “news”.

  5. My theme adds the CSS class `.current-menu-item`.

    Might be different depending on the theme, but the process is still the same.

  6. works like a charm, and saved me some valuable time. Thanks

  7. Thank you so much!!!!

  8. halo sir, its good but i want to change link color not back ground color plz help me

    1. The color would be controlled by the color property, such as:

      li.current_page_item a{
      color:#666;
      }

  9. i think you only need to add this to your CSS and not the functions.php page. It worked just fine in my CSS.

    Thank you

    1. Thanks, the snippet has now been updated.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!