Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Add Username to Menu


  • barkins
    Participant

    @barkins

    Hello,

    Is there a way to add a Logged In Username to the menu in a specific location?

    I have seen Hooks that add them to the end of the menu, but I need one added to a specific location in the menu.

    Any plugin that will work within Appearence -> Menu area? Thanks in advance.

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

  • Henry Wright
    Moderator

    @henrywright

    wp_nav_menu_items is a useful filter hook. You can use it like this:

    add_filter( 'wp_nav_menu_items', function( $items, $args ) {
        if ( 'primary' === $args->theme_location ) {
            // Do something to the primary menu's $items.
        }
        return $items;
    } );

    Boone Gorges
    Keymaster

    @boonebgorges

    Not sure if this is directly related to what you’re trying to do, but I wrote a post about dynamically adding items to a WP menu a couple years ago, which demonstrates some of what Henry has mentioned above: https://teleogistic.net/2013/02/11/dynamically-add-items-to-a-wp_nav_menu-list/

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar