[Resolved] mobile styles and scripts

Home Forums Support [Resolved] mobile styles and scripts

Home Forums Support mobile styles and scripts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #996448
    Ronny

    Hi guy’s,

    I have the following menu setup: on desktop i have the primary and secondary menu and on mobile i use the offset menu.

    I noticed the sticky and secondary script are loaded on mobile and offsite is loaded on desktop. So i created this script to dequeue where applicable:
    function conditional_mobile_styles_scripts() {
    if ( function_exists( ‘wp_is_mobile’ ) ) {
    if ( wp_is_mobile() ) {
    wp_dequeue_script( ‘generate-sticky’ );
    wp_dequeue_style( ‘generate-sticky’ );
    wp_dequeue_style( ‘generate-secondary-nav-mobile’ );
    wp_dequeue_style( ‘generate-secondary-nav’ );
    } else {
    wp_dequeue_style( ‘generate-offside’ );
    wp_dequeue_script( ‘generate-offside’ );
    }
    }
    }
    add_action( ‘wp_enqueue_scripts’, ‘conditional_mobile_styles_scripts’, 1500 );

    1. When i test the site in desktop and mobile all seems to work fine but i just wanted to double check if i am not breaking any functionality this way?

    2. I noticed the following scripts: ‘/generatepress/css/mobile.min.css?ver=2.3.2′ Is these only used on mobile devices? Can i dequeue this on destop?

    3. And these: /generatepress/js/menu.min.js?ver=2.3.2’ Is this used offsite menu as well?

    Thanks!

    #996818
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. That looks good to me. You will want to keep an eye on updates just in case those handles change at some point.

    2. Some of the CSS in there is within a media query, but the entire file is loading on desktop and mobile. You might be able to dequeue it on desktop if you don’t need any of the CSS inside it.

    3. No, that file is mostly for your mobile menu, but also has some accessibility stuff in it for the desktop menu.

    #997083
    Ronny

    Hi Tom,

    I ended up with:

    function conditional_mobile_styles_scripts() {
    // GP related scripts
    if ( function_exists( ‘wp_is_mobile’ ) ) {
    if ( wp_is_mobile() ) {
    wp_dequeue_script( ‘generate-sticky’ );
    wp_dequeue_style( ‘generate-sticky’ );
    wp_dequeue_style( ‘generate-secondary-nav’ );
    } else {
    wp_dequeue_style( ‘generate-mobile-style’ );
    wp_dequeue_style( ‘generate-offside’ );
    wp_dequeue_script( ‘generate-offside’ );
    }
    }
    wp_dequeue_style( ‘generate-secondary-nav-mobile’ );
    }

    All seems to work fine!

    Thanks,
    Ronny

    #997331
    Tom
    Lead Developer
    Lead Developer

    Awesome 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.