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

1 Answer 1


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 {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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