Add active class to a menu link with WordPress


Staff member
I am using the WordPress function <strong>wp_nav_menu</strong> to create my main menu.

In this menu, I have a link named "News" for exemple and I would like to make this link highlight when I am in the single.php file template.

At the moment, my code is the one below. I am not "used" to work with this WordPress function.

&lt;?php wp_nav_menu( array( 'theme_location' =&gt; 'primary', 'menu_class' =&gt; 'nav-menu' ) ); ?&gt;

Is there any way to said for exemple

echo 'class="active"';

I have checked arround on SO and I founded some informations that might be interesting but nothing is really answering my question.

On this page, some one suggest to check in "Show on screen" options : <a href="">add class to dropdown menu inside dynamic wordpress menu</a>

<img src=" " alt="enter image description here">

I also found this page in the codex, but I'm not sure how to use it : <a href="" rel="nofollow noreferrer"></a>

Thx in advance for the help!