Skip to content

Instantly share code, notes, and snippets.

@ideag
Created July 12, 2015 07:45
Show Gist options
  • Save ideag/63ec21da36c2684dd3af to your computer and use it in GitHub Desktop.
Save ideag/63ec21da36c2684dd3af to your computer and use it in GitHub Desktop.
Vary menu based on some logic (user role, current page, etc.)
<?php
// ...
register_nav_menu( 'primary', __( 'Primary default location', 'yourtheme' ) );
register_nav_menu( 'primary-subscriber', __( 'Primary subscriber location', 'yourtheme' ) );
register_nav_menu( 'primary-account', __( 'Primary account location', 'yourtheme' ) );
// ...
?>
<?php
// ...
$args = array(
'theme_location' => 'primary',
);
if ( current_user_can( 'read' ) && !current_user_can( 'edit_user' ) ) {
$args['theme_location'] = 'primary-subscriber';
$args['walker'] = new Your_Walker_Class;
}
if ( is_page('account') ) {
$args['theme_location'] = 'primary-account';
}
wp_nav_menu( $args );
// ...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment