I am building a custom theme. For the author.php file that displays an author profile with their posts, I would like my 'About' menu item to turn active (get active class).

I have tried:

add_filter('nav_menu_css_class', 'filter_handler', 10, 2);

but can't get it to work because author.php is not associated with any WordPress pages and is using default wordpress template.

Is there any workaround to it?

  • Without the filter_handler function it's impossible to see what's not working, so you should add that code. Sep 27, 2014 at 13:07

1 Answer 1


Two built-in features of WordPress make this easy to accomplish, without any code: body tag classes, and the ability to add a class to a menu item.

Any author archive pages will have the classes 'archive' and 'author' in the tag (along with others, including author-name and author-id).

You can add a class to a menu item by opening the Screen Options tab on the menu page and clicking the 'CSS Classes' checkbox. Add a class name and save the menu.

In your CSS, you can then target that menu item when the body tag has 'author' class.


body.author .menu-item.myclassname { active state rules here }

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.