Tell me more ×
WordPress Answers 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

1 Answer

Add a class in your css file.

If your menu is in a div called for example navigation, add this:

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

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.