Using MeanMenu Mobile with Genesis Theme

This guide goes through using the lightweight jquery mobile menu meanmenu  in a Genesis Theme based on the Sample Theme.

 

meanmenu-contracted

Menu Contracted

 

meanmenu-expanded

Menu Expanded

Get the Assets

Download the latest version of meanmenu from GitHub. Need to get two files in your child theme and also create a jquery initialise script.

Move – jquery.meanmenu.min.js into your child theme js folder

Move – meanmenu.min.css into your child themes css folder

Create a jquery initialise script to load in the footer, so the menu can be targeted and fired at a certain media breakpoint size

So for example in the Genesis Sample Theme the default menu is the nav in the header, this is selected in the initialise script.

Enqueue the MeanMenu Scripts

<?php
//do not copy the opening php tag
//Load MeanMenu Mobile Menu
function meanmenu_load_scripts() {
wp_enqueue_script( 'meanmenu', get_stylesheet_directory_uri() . '/js/jquery.meanmenu.min.js', array( 'jquery' ), '2.0.8', true );
wp_enqueue_style( 'meanmenucss',get_stylesheet_directory_uri() .'/css/meanmenu.min.css', '', '2.0.8', 'all' );
}
add_action( 'wp_enqueue_scripts', 'meanmenu_load_scripts' );
function meanmenu_load_scripts_init() {
echo ' <script>jQuery(document).ready(function () {
jQuery("header nav").meanmenu({
meanScreenWidth: "480",
meanMenuContainer: "body",
meanMenuClose: "X",
meanMenuCloseSize: "18px",
meanMenuOpen: "<span /><span /><span />",
meanRevealPosition: "right",
meanRevealPositionDistance: "0",
meanRevealColour: "",
meanNavPush: "",
meanShowChildren: true,
meanExpand: "+",
meanContract: "-",
meanRemoveAttrs: false,
onePage: false,
removeElements: "",
meanDisplay: "block"
});
});</script>
';
}
add_action( 'wp_footer', 'meanmenu_load_scripts_init', 20 );
view raw meanmenu.php hosted with ❤ by GitHub
@media only screen and (max-width: 800px) {
/* # Mean Menu
-------------------------------------------- */
.mean-nav .genesis-nav-menu {
line-height: 1.6;
}
.mean-nav .genesis-nav-menu .menu-item:hover {
position: relative;
}
.mean-nav .genesis-nav-menu .sub-menu {
width: 100%;
position: relative;
left: 0;
opacity: 1;
}
.mean-nav .sub-menu a {
background-color: transparent;
font-size: inherit;
border-top: 1px solid rgba(255,255,255,.25);
border-bottom: none;
border-left: none;
}
}
view raw meanmenu_css.css hosted with ❤ by GitHub

Once you have the two files in place, load them via your functions.php file.

That is the first block of code above.

The meanmenu has a number of jquery variables that can be used, the ones above are the defaults, you will need to change the target menu and pixel breakpoint size to show and any other settings. For more description on the values see the explanations on the github page.

Alter Some Genesis Menu CSS

For the CSS to work, some tweaks will need to be done at the same media breakpoint size, so if you set the menu to appear at 800px then a corresponding media query CSS would need to be added. This is in the second part of the above code which would go in your style.css

Demo here with the meanmenu set to trigger at 800px.

 

Leave a Comment