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).
where do i find the “theme’s style.css file” on the wordpress free version?
Thank you. I have looked in a few places, but your solution worked. I really appreciate it!
Hey Robert, glad our solution worked for you.
Please follow us on Facebook and Twitter for more interesting guides. 🙂
Work’s fine thanks !
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”.
My theme adds the CSS class `.current-menu-item`.
Might be different depending on the theme, but the process is still the same.
works like a charm, and saved me some valuable time. Thanks
Thank you so much!!!!
halo sir, its good but i want to change link color not back ground color plz help me
The color would be controlled by the
color
property, such as:li.current_page_item a{
color:#666;
}
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
Thanks, the snippet has now been updated.