Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rocket-martue/dbc2a31ec4fadf4e864eab4401338efa to your computer and use it in GitHub Desktop.
Save rocket-martue/dbc2a31ec4fadf4e864eab4401338efa to your computer and use it in GitHub Desktop.
add_action(
'after_setup_theme',
function() {
register_nav_menus(
[
'global-nav-2' => esc_html__( 'Global Navigation 2 (For PC)', 'snow-monkey' ),
'drawer-nav-2' => esc_html__( 'Drawer Navigation 2 (For Mobile)', 'snow-monkey' ),
'global-nav-3' => esc_html__( 'Global Navigation 3 (For PC)', 'snow-monkey' ),
'drawer-nav-3' => esc_html__( 'Drawer Navigation 3 (For Mobile)', 'snow-monkey' ),
]
);
}
);
// メニューの差し替え
add_filter(
'wp_nav_menu_args',
function ( $args ) {
if ( 'global-nav' === $args['theme_location'] ) { // どのナビゲーションを差し替えるか
if ( is_page( $page-3 ) ) { //(mixed)ナビゲーションを差し替える固定ページの ID、タイトル、スラッグ、またはそれらの配列
$theme_location = 'global-nav-3';
} elseif ( is_page( $page-2 ) ) {
$theme_location = 'global-nav-2';
} else {
$theme_location = 'global-nav';
}
$args['theme_location'] = $theme_location;
} elseif ( 'drawer-nav' === $args['theme_location'] ) {
if ( is_page( $page-3 ) ) {
$theme_location = 'drawer-nav-3';
} elseif ( is_page( $page-2 ) ) {
$theme_location = 'drawer-nav-2';
} else {
$theme_location = 'drawer-nav';
}
$args['theme_location'] = $theme_location;
}
return $args;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment