Support » Fixing WordPress » Want to add an id element to ahref in menu

  • Resolved trishzwei

    (@trishzwei)



    I’d like to add an id element to the menu anchor tags. This is what is currently generated:
    <a title="About" href="http://trishladd.com/wordpress/about/">About</a>
    I would like it to generate the following:
    <a id="About" title="About" href="http://trishladd.com/wordpress/about/">About</a>

    I tried adding this line of code in the nav-menu-template.php
    $attributes = ! empty( $item->attr_title ) ? ' id="' . esc_attr( $item->attr_title ) .'"' : '';

    But it didn’t change the end result one bit. I’m assuming there is something I am missing somewhere. Any advice on this would be great! Thanks!
    -Trish

Viewing 9 replies - 1 through 9 (of 9 total)
  • trishzwei

    (@trishzwei)

    Hey I know volunteers are supposed to be working on this board and what not, but at this point I am wondering if any one even saw this… I’d appreciate any kind of response so I at least know people have seen this. I posted it in the middle of the night and maybe no one saw it. Thanks.

    esmi

    (@esmi)

    Don’t edit WordPress core files! If you use wp_list_pages(), wp_page_menu() or wp_nav_menu(), your links will have unique ids.

    trishzwei

    (@trishzwei)

    where do I find these functions?

    I’m using twenty-ten as a base reference and I found the following in the header:
    wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
    That is the wp_nav_menu() you reference above? I went searching in the functions.php page to see if I could figure out what the text above was referencing – that eventually took me to the nav-menu-template.php page where I found the above code I mentioned.

    I’m a baby coder – can you explain what the array is referencing? Is the ‘menu-header’ what I want to look more closely at?

    Thanks!

    esmi

    (@esmi)

    In Twenty Ten, you need to be looking in header.php.

    trishzwei

    (@trishzwei)

    I found the wp_nav_menu() in the header.php page. It was what lead me to look in the functions page (since I knew that the wp_nav_menu() was a function) – the other functions you mention are not in header.php

    I still do not know how to utilize the information in the array in the wp_nav_menu() function in order to have it generate html code as I want. There are no ids generated from this code, most especially the home page. I’d still like to have ones that have the same id as the titles in the links. (As per my specification at the start of this post)

    I don’t think it should be that hard, but do you have any idea of how I can do what I asked?

    Thanks!

    Did anyone find a solution to trishzwei’s request? I also would like to generate n id element on my menu links.

    Thanks,
    Rodrigo

    I ended up finding a different solution for what I wanted to do. But no one answered after this. Thanks for asking.

    May I know the solution you found? It may still assist me and hopefully others as well.

    I was trying to stylize buttons in the menu with images. I thought I needed to go about it a specific way (the method I was trying up above — I wanted to use id to use it in the CSS) but after awhile I discovered that the menu list items did indeed have a unique class that I could use instead of id to affect them individually.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Want to add an id element to ahref in menu’ is closed to new replies.