This is what worked for me (based on this).. hope it will be helpful for others too..
add_filter( 'wp_nav_menu_items','primary_navigation', 10, 2 );
function primary_navigation( $items, $args ) {
if( $args->theme_location == 'primary_navigation' ) {
if ( ! isset( $_SESSION['menu_country'] ) ) {
$country = json_decode( file_get_contents(
"http://freegeoip.net/json/" . esc_url( $_SERVER['REMOTE_ADDR'] )
) );
$_SESSION['menu_country'] = strtolower( $country->country_code );
}
$items .= '<li class="menu-produkte"><a href="https://wordpress.stackexchange.com/" .
esc_url( $_SESSION['menu_country'] ) .'/shop">Produkte</a></li>';
}
return $items;
}
Related Posts:
- Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?
- How make top level menu item not have link, but have sub-menus that are linked?
- How to Hard Code Custom menu items
- Generate a Menu that Displays Child Pages using wp_list_pages() with the New Menu Functionality in WordPress 3.0?
- How Does The Walker Class Work?
- Calling the Menu Title within wp_nav_menu array function
- How to stop mobile theme inheriting desktop navigation menu?
- How to hide an item from a menu to logged out users (without a plugin)
- Large WP 3.0 menu times out and won’t save
- How do I add the data-toggle=”modal” data-target=”#myModal” attribures to a WP Nav bar?
- How to apply a class to the second word in menu list item?
- How to switch between the Primary Menus programmatically?
- if role is logged in then do something
- Generate a Menu that displays all child pages of top level parent
- Terms with more than one occurrence have current-menu-item class in menu
- Nav menu items disappearing (but not immediately)
- start_lvl on Walker is not working
- How to get Menu Navigation Labels to output HTML
- custom menu not found
- How to add text before WordPress menu item href
- Nav walker, bootstrap: Display 3rd level items under 2nd level
- Remove nav_menus from customizer using a theme
- Pending Custom Link in Menu
- Benefits of using Nav Walker?
- display only the wp_nav_menu, which has the current-menu-item
- Add tabindex to navmenu
- wp_list_pages sort order is different for different languages [closed]
- has_children in custom nav_walker
- I’m having a lot of trouble since upgrade to 3.0.1 with get_page_children() function
- How can I add a link to a WPForms “contact us” form to the main menu?
- How to add wechat (weixin) link to navigation menu?
- Create search form in menu as in Twenty Fourteen theme
- WordPress get or set active menu class
- How to have two menus using Bootstrap nav walker?
- switch_to_blog() and wp_nav_menu() not functioning properly
- Generating wordpress menu – cant understand the config
- SlideDeck 2, make back-end visible for admins only
- How to add ID attribute to each submenu?
- Display menu locations in all sites of a multi site
- Making a navigation header menu with bulma, need some advice
- From a page, is it possible to find entry’s “menu_item_parent”?
- WordPress menu link not working
- target nav class in wp_nav_menu
- How to retrieve parent menu item name of current submenu item
- Determine the last child of the parent menu WP Nav Walker
- Admin menu structure
- Navigation doesn’t render when wp is hosted
- WordPress menu performance is slow when lot of items [closed]
- HTML list menu to WordPress menu
- Does is_child() exist in wp 3.5.1?
- Add “drop-down arrow” for menu items with sub-menus
- Main menu gets replaced when second menu is created
- Hide menu items if the page content is empty
- Output menu title
- Add Labels to Admin Menu ( How To )
- exclude pages in custom menu
- Adding new pages to Menu
- How to reference argument data for wp_nav_menu() from functions.php
- Hamburger Menu not working on reduced browser size
- WordPress functions.php does not affect the theme menus
- Showing the same menu in multiple location
- wp_nav_menu with WP as pure CMS
- Simple form to add custom links to menu?
- Wrap wp_nav_menu output around option tags for select menu
- What’s the best way to customize the WordPress Menu Page (in admin)
- Catagorized hierarchy menu for PAGES!
- Making the menu toggled open on mobile devices Illustratr theme
- How to include second layer sub menu to Walker Nav?
- need help in wordpress navbar setup
- Event listener callback returns undefined element
- Add class to sub-menu from unrelated element
- How can I creat custom menu with bootstrap
- Add CSS Class to WordPress Menu Item Dependent on the Page the User is Visiting
- Restrict user to edit only edit a certain menu
- Menu walker: how to tell if a sub menu contains submenus?
- How do i make a custom top level dashboard menu item available for all users?
- Migrate old blogroll to menus automatically
- Getting parent object_id of child menu items in WordPress menu
- How to remove a sub-menu using walker hooks/filters without relying on a custom walker?
- Walker or wp_get_nav_menu_items VS jQuery
- Calling wordpress menu outside ignores custom menu item
- Specific Page that convert Hyperlink to anchor in nav menu
- How can I make this custom design menu work in wordpress?
- Active menu item / category
- Add different span class to wp nav menu
- Disappearing items in menu
- Custom Menus and taxonomies
- Help with changing style of the extended menu drop down [closed]
- Where these arguments are defined?
- How we show pages in dropdown
- Menu support for touch devices
- WordPress Flyout Menus
- wp_nav_menu doesn’t show on index page
- Automatically add new posts to a specific menu name
- Elegant way of adding an CTA to a menu
- highlight parent page on menu when child page is on sidebar (and not on menu)
- How to set menu Display location
- How to add custom menu to block theme?
- get menu name for the current displayed page
- Menu problem : when add wordpress element in menu it convert into empty custom link