Site logo

Archived topic

How to add custom menu item onto a menu in the Top Bar?

7 replies · Started by William on December 19, 2020

Viewing posts 1–8 of 8

Hi there,

Any chance you can link us to the site in question?

You can use the private information field.

Let me know :)

URL provided in private info, thanks.
The goal is to keep this a menu.

Hi there,

the generate_menu_bar_items only exists inside the Primary Nav and Mobile Header.

For you top bar menu - is it the Email link you wish to add ? If so can simply add a Custom Link to your menu to include the Email label and add your mailto:"email-address" as the menu items URL.

Let me know,

Shouldn't this work - if I could somehow figure out the theme_location for a menu that I put in the Top Bar?

add_filter( 'wp_nav_menu_items', function( $nav, $args ) {
    if ( $args->theme_location == 'topbar_nav_menu' ) {
        return $nav . '<span class="menu-bar-item">Email: <a href="#">person@domain.com</a></span>';
    }
    return $nav;
}, 10, 2 );

Navigation widgets don't have a theme_location as they are a widget
Why not just use the method i suggested with adding it as a menu item ?

Okay, thanks I've done that.

Using this CSS should help in case the client adds another menu item (just as long as it's not the last menu item).

.menu-top-bar-container .menu > li:last-child:before {
    content: "Email: ";
}

You can add HTML to your Menu item label as well

eg.

<span class="email-label">Email: </span>youremail@wherever.com

Glad you its working for you.

This archived topic is closed to new replies.