Skip to content

Instantly share code, notes, and snippets.

@WPDevHQ
Last active January 16, 2017 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save WPDevHQ/c32f7d36d6b5daffcda4a2b4b343a1a1 to your computer and use it in GitHub Desktop.
Save WPDevHQ/c32f7d36d6b5daffcda4a2b4b343a1a1 to your computer and use it in GitHub Desktop.
Show standard or humburger menu on desktop depending on user selection in customizer
<?php
if ( get_theme_mod( 'menu-style' ) == A ) {
//Output standard menu
$handle = 'themeprefix-style';
$menu_style = '.main-navigation{ display: block; } .menu-toggle{ display: none; } ';
wp_add_inline_style( $handle, $menu_style );
} else {
//Output mobile menu
$handle = 'themeprefix-style';
$menu_style = '.main-navigation{ display: none; } .menu-toggle{ display: block; } ';
wp_add_inline_style( $handle, $menu_style );
}
@WPDevHQ
Copy link
Author

WPDevHQ commented Jan 14, 2017

The above code would go inside a function callback which should be hooked to wp_enqueue_scripts via the add_action method. You may need to adjust class .main-navigation and .menu-toggle to match those of your theme.

P.S. You still need to take into account of the desktop view version not showing on mobile in the case of the output view being the standard view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment