Action Hooks

shiftnav_before

Inject PHP before the menu within the ShiftNav Panel. The $id argument is the ID of the ShiftNav instance.

add_action( 'shiftnav_before' , 'sn_before_menu', 10, 1 );
function sn_before_menu( $id ){
 
    // Target the main panel
    if( $id === 'shiftnav-main' ){
        echo 'My Custom Content Before Menu';
    }
}

shiftnav_after

Inject PHP after the menu within the ShiftNav Panel. The $id argument is the ID of the ShiftNav instance.

add_action( 'shiftnav_after' , 'sn_after_menu', 10, 1 );
function sn_after_menu( $id ){
 
    // Target the main panel
    if( $id === 'shiftnav-main' ){
        echo 'My Custom Content After Menu';
    }
}

Example: Add a secondary menu in the panel

Here’s some example code to add a secondary menu after the primary menu in the mobile menu panel:

// Inject a secondary menu into the panel after the primary menu
add_action('shiftnav_after', 'sn_after_inject_menu');
function sn_after_inject_menu($id)
{
	// Add menu only to main panel
	if ($id === 'shiftnav-main') {
		$args = array(
			'menu' => 31,		// Change to ID of menu to include
			'shiftnav' => $id,
		);
		$args = shiftnav_get_menu_args($args, $id);
		echo '<!-- shiftnav_after: Begin secondary menu -->';
		wp_nav_menu($args);
		echo '<!-- shiftnav_after: End secondary menu -->';
	}
}

Replace the “31” with the ID of the menu you want to display, or the ‘shiftnav-main’ with the ID of the ShiftNav configuration you’d like to target.

On this page