Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.