• As the title says I am trying to target a specific menu item with a class but it simply does not output into the html.

    Is it possibly how I am calling the wp_nav_menu?

    <?php wp_nav_menu( array( ‘theme_location’ => ‘headernav’) ); ?>

    Any help would be appreciated, cant find any answers anywhere…

Viewing 8 replies - 1 through 8 (of 8 total)
  • Site url?

    Thread Starter AMCD

    (@amcd)

    Developing it locally…

    Have you set up & added a custom menu?

    Thread Starter AMCD

    (@amcd)

    my bad:

    <nav id="headnav">
    <ul>
    <li><a href="http://localhost/amc/products/">Products</a></li>
    <li><a href="http://localhost/amc/services/">Services</a></li>
    <li><a href="http://localhost/amc/locations/">Locations</a></li>
    <li><a href="http://localhost/amc/contact/">Contact</a></li>
    </ul>
    </nav>

    As you can see… pretty standard stuff… just wont output the class

    No – that’s not a WordPress custom menu. See custom menus.

    Thread Starter AMCD

    (@amcd)

    Yup…. this is being generated by a custom menu

    Functions.php:

    if ( function_exists( 'register_nav_menus' ) ) {
    register_nav_menus(
    array(
    'headernav' => __( 'Header Navigation' ),
    'footernav' => __( 'Footer Navigation' )
    )
    );
    }

    Calling in template:

    <nav id="headnav">
    <?php wp_nav_menu( array( 'theme_location' => 'headernav') ); ?>
    </nav>

    The code you listed above is not being generated by wp_nav_menu().

    Thread Starter AMCD

    (@amcd)

    Your right… I did some digging and found this in my functions.php

    function remove_css_selector_attributes($input) {
      return preg_replace('/ (id|class)=\"(.*?)\"/', '', $input);
    }
    add_filter( 'wp_nav_menu', 'remove_css_selector_attributes' );

    Added by the original author of the blank theme template I’m using… in order to clean up the garbage classes WP ads to the menu code I presume.

    Thanks for your help!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘CSS Classes (optional) not outputting to source’ is closed to new replies.