• Hi,
    I need some help on creating a custom link to a dynamically changing url based off the user id.
    What I am trying to do is create a menu item called “Profile” that links to the Author page. Because it is different for every user, it will be a dynamically changing url.
    I know the way to link to the author page through php and html using this:
    <a href="<?php the_author_posts_link(); ?>"</a>

    So, how do I modify a menu item to link to this particualr tag?

    Any help would be appreciated.
    Thanks

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If your theme uses wp_nav_menu() to output the nav menu, then you can use the ‘wp_nav_menu’ filter to alter the menu HTML. Your callback is passed the actual HTML for the menu and an object of menu arguments.

    If your site has more than one nav menu, check the arguments object to ensure you are modifying the correct menu. Also examine the current menu HTML to see how the current items are organized so you can replicate the same structure, otherwise your added element will not be styled like the rest of the menu.

    You can use str_replace() to insert your item by replacing the final </ul> with your item’s HTML (including <li>, </li> and any classes) with a new </ul> concatenated to the end.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Menu Item Attributes’ is closed to new replies.