PHP API

ShiftNav provides two functions that developers can use to generate ShiftNav components.

shiftnav()

The shiftnav() function generates a ShiftNav menu panel (the part that slides out from the side of the viewport).

Basic usage

Pass the function the ID of an instance in order to generate the panel based on those instance styles.

The default instance is shiftnav-main. So to generate the main ShiftNav instance panel, you would use

shiftnav( 'shiftnav-main' );

The ShiftNav panels should be added in the footer. So this function will almost always be called within a wp_footer callback

add_action( 'wp_footer' , 'my_shiftnav_api' );
function my_shiftnav_api(){
	shiftnav( 'shiftnav-main' );
}

Use case: precision menu integration

Out of the box, all ShiftNav instances will automatically be generated and added to the footer of the site on every page.

If you would like more precise control over which pages the menus are generated on, you can unhook the automatic menu generation and manually integrate each instance.

For example, the code below will remove all of the automatically generated instances beside the main instance. Then it will add the custom ‘shop’ instance only on page 52.

//Remove the ShiftNav automatic menu integration (secondary instances)
add_action( 'wp' , 'my_remove_auto_menu_integration' , 20 , 0 );
function my_remove_auto_menu_integration(){
	remove_action( 'wp_footer' , 'shiftnav_pro_generate_menus' );
}

//Add ShiftNav to specific pages (secondary instances)
add_action( 'wp_footer' , 'my_precision_integration' );
function my_precision_integration(){
	if( is_page( 52 ) ){
		shiftnav( 'shop' );
	}
}

This could be expanded to generate any number of custom instances only under specific conditions – e.g. logged in users, specific pages, specific sections of a site, etc.

If you would like to disable ShiftNav entirely on a page, see Disable ShiftNav on a specific page (or any custom condition)

Custom Settings

The shiftnav() function also takes an optional second argument which is an array of settings. These settings can override options set in the instance Control Panel settings, specifically theme_location, menu, container, edge, and skin. This way if you want to change one of these particular settings without creating an entire new instance, you can do so.

shiftnav_toggle()

The shiftnav_toggle() function will generate a ShiftNav toggle for a specific ShiftNav instance – an element that, when clicked, will open the ShiftNav panel for that instance.

Basic usage

Pass the function the ID of an instance in order to generate a toggle which will control that instance.

The default instance is shiftnav-main. So to generate a toggle for the main ShiftNav instance panel, you would use

shiftnav_toggle( 'shiftnav-main' );

Content

By default, the toggle will contain the content of the Toggle Content setting for this instance from the Control Panel settings.

If you wish to override this content, you can pass a second argument to the function.

The default instance is shiftnav-main. So to generate the main ShiftNav instance panel, you would use

shiftnav_toggle( 'shiftnav-main' , 'my custom toggle content' );

Placement

Place the toggle anywhere in your layout. Note that each instance generates your shortcode, HTML, and PHP versions of this toggle in the Control Panel. See Toggles for more info.

On this page