• I’m developing a WordPress theme from scratch and I’m looking to add an active class to the navigation. I’ve found lots of articles for adding it to a WordPress menu that uses ul and li, but I’m using HTML5 nav and a for the navigation and can’t find how to add class=”active” to the active link.

    The PHP code below is what I’m using to call the menu in the themes header.php file:

    $headerNavigation = array (
      'menu'       => 'navigation',
      'container'  => 'nav',
      'echo'       => false,
      'items_wrap' => '%3$s',
    );
    echo strip_tags(wp_nav_menu( $headerNavigation ), '<a><nav>' );

    I’m using the following code to register the navigation in the functions.php file:

    function register_my_menus() {
      register_nav_menus(
        array(
          'header-navigation' => __( 'Header Navigation' )
        )
      );
    }

The topic ‘Add Active Class to Active WordPress Navigation Link’ is closed to new replies.