Enqueue Theme Navigation Scripts Conditionally

A lot of themes include some kind of responsive navigation script. While it feels wasteful to delete that entirely, it feels even more so to load scripts you’re not using, so here’s how I load my theme navigation files only if SuperSide Me is not active:

add_action( 'wp_enqueue_scripts', 'prefix_load_scripts' );
function prefix_load_scripts() {

    if ( function_exists( 'supersideme_has_content' ) && supersideme_has_content() ) {
    wp_enqueue_script( 'leaven-responsive-menu', get_stylesheet_directory_uri() . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0', true );

    $output = array(
        'mainMenu' => 'Menu',
        'subMenu'  => 'Menu',
    wp_localize_script( 'leaven-responsive-menu', 'LeavenL10n', $output );

}Code language: PHP (php)

We check to see if SuperSide Me is active, and also to see if the menu panel can be generated. If it can, then there is no need to load the theme’s responsive navigation script.

Return to SuperSide Me