WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to add a conditional menu item such as "/at" or "/de" or "/ch" in the wp_nav_menu. Since the link is conditional (based on the country the website is being viewed), it can't be added from the backend but instead has to be hardcoded.

How do I add this new conditional link at the end of what the wp_nav_menu is populating? Thank you.

share|improve this question
I see this is what I want.. wpbeginner.com/wp-themes/… – sushil May 7 '14 at 6:48

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/".$_SERVER['REMOTE_ADDR']));
            $_SESSION['menu_country'] = strtolower($country->country_code);   

       $items .=  '<li class="menu-produkte"><a href="/'.$_SESSION['menu_country'].'/shop">Produkte</a></li>';
    return $items;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.