Skip to content

Instantly share code, notes, and snippets.

@jakefentress
Last active August 29, 2015 14:06
Show Gist options
  • Save jakefentress/f89ad11ad1fe01656aa2 to your computer and use it in GitHub Desktop.
Save jakefentress/f89ad11ad1fe01656aa2 to your computer and use it in GitHub Desktop.
Pass an argument to a WordPress nav walker function.

One other way involves adding a custom argument to the wp_nav_menu() function. This is handy if you need to pass a value from outside of the walker class altogether:

wp_nav_menu( array( 
    'theme_location' => 'secondary',
    'depth' => 1,
    'walker' => new Custom_Walker(),
    'walker_arg' => 'Custom argument value here'
) );

From within the walker class you can then access this custom arg from within start_el() function inside of the walker class (Walker_Nav_Menu::start_el()) like this:

$custom_arg = esc_attr( $args->walker_arg );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment