• I’m trying to get a menu working without the container, ul, and li. My end goal is:

    <a class="hp_signnav" id="services" href="linkhere"></a>
    
    <a class="hp_signnav" id="packages" href="linkhere"></a>
    
    <a class="hp_signnav" id="portfolio" href="linkhere"></a>
    
    <a class="hp_signnav" id="products" href="linkhere"></a>

    By using the PHP code:

    $menuParameters = array(
      'theme_location'  => 'homepage-menu',
      'echo'            => false,
      'fallback_cb'     => '',
      'items_wrap'      => '%3$s',
      'depth'           => 0,
    );
    
    echo strip_tags(wp_nav_menu( $menuParameters ), '<a>' );

    I got to here (with corrent hrefs):

    <a href="linkhere"></a>
    
    <a href="linkhere"></a>
    
    <a href="linkhere"></a>
    
    <a href="linkhere"></a>

    I then added this in my functions file to add a class to each, but it is a static class.

    function add_nav_class($output) {
        $output= preg_replace('/<a/', '<a class="hp_signnav" id=""', $output, -1);
        return $output;
    }
    add_filter('wp_nav_menu', 'add_nav_class');

    That got me to here:

    <a class="hp_signnav" href="linkhere"></a>
    
    <a class="hp_signnav" href="linkhere"></a>
    
    <a class="hp_signnav" href="linkhere"></a>
    
    <a class="hp_signnav" href="linkhere"></a>

    So I need help with two things. How can I add the slug of the page to the ‘s ID? Also, can I change the filter so that it only applies these to a single menu?

    Thanks for the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Could you use the Menu system to assign the class to your menu items as described here?

    Then if your hrefs contain the page slug, in your filter you could check for the assigned class and if it is set, use preg_match to get the slug to create the ID.

    Thread Starter Andy Mercer

    (@kelderic)

    The menu system lets you add custom classes to the li containers, not the actual a’s. Since I’m filtering out the li and ul, that doesn’t help. I ended up using a custom walker to change the actual menu function.

    Thanks for the help though!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_nav_menu’ is closed to new replies.