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'm creating a menu with the wp_nav_menu() function. Now I'd like to add a GET variable to the end of ever link in the menu, like this: www.mysite.com/page/?variable=123

Is there any way I can do this when using wp_nav_menu?

Thanks for your suggestions

share|improve this question
up vote 1 down vote accepted

Filter 'wp_nav_menu_objects'. You get an array as argument, a list of all items.

Pseudo-code, not tested:

add_filter( 'wp_nav_menu_objects', 'wpse_76401_filter' );

function wpse_76401_filter( $items )
    $out = array();
    foreach ( $items as $item )
        if ( isset ( $item->url ) )
            $item->url = add_query_arg( 'variable', '123', $item->url )

        $out[] = $item;

    return $out;
share|improve this answer
Tried that and it does exactly what I need – perfect solution. Thanks a lot! – Max Min Dec 17 '12 at 16:52

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.