Support » Plugins » Adding URL parameters to menu items

  • Resolved hydrurga


    I currently use 2 menus on my site, defined through Appearance->Menus, each menu written in a different language. I use my own PHP code to distinguish between the 2 when generating a page:

    <?php switch($_SESSION['lang']) {
     case 0: wp_nav_menu(array('theme_location' => 'primary')); break;
     case 1: wp_nav_menu(array('theme_location' => 'primary', 'menu' => 'French Menu'));
    } ?>

    The French pages can be obtained by e.g.

    The above works well but the principal question is this: does anyone know of a way, without hard-coding WP core, that I can have the French menu automatically append an URL parameter on to the end of all of its menu items?

Viewing 2 replies - 1 through 2 (of 2 total)
  • For further info, the hard-coding of WP core that I would like to avoid, but which I am currently forced to use, is the changing of line 86 of wp-includes\nav-menu-template.php


    $attributes .= ! empty($item->url) ?(' href="'.esc_attr($item->url).(($_SESSION['lang']==1)?'?language=1':'').'"'):'';

    using the php session variable that I set up depending on the current language choice.

    In the end, I decided to create a series of custom links in the French menu, specifying URLs containing the ?language=1 parameter. A bit of work involved, but it prevents issues arising from directly editing the WP core. Marking as resolved.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding URL parameters to menu items’ is closed to new replies.