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

Comments  Leave a Reply

  1. 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!
[LIMITED TIME]
[LIMITED TIME]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF TODAY!]
[50% OFF TODAY!]
[60% OFF Today!]
[60% OFF Today!]
[50% OFF Today!]
[50% OFF Today!]