WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how can i add css class on current page in wordpress wp_nav_menu

For Example I Want To Use It In Wordpress wp_nav_menu

<li><a href="index.php?id=index&colortheme=green" class="selected" title="Home">Home</a></li>

Wordpress Code

<?php $menu_args = array('menu' => 'Header' ); wp_nav_menu( $menu_args ); ?>

Using This Function

function add_nav_class($output) {
$output= preg_replace('/<a/', '<a class="selected"', $output, 1);
return $output;
add_filter('wp_nav_menu', 'add_nav_class');

but this function select only home and not highlight current page item thanks in advance

share|improve this question

WordPress already adds a class for this purpose called .current-menu-item so just target this class in your css file.

For example, if your menu is in a div with an ID of navigation, add this:

#navigation .current-menu-item {}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.