[Support request] No background video on Mobile

Home Forums Support [Support request] No background video on Mobile

Home Forums Support No background video on Mobile

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2218950
    Brenden

    I’m using this https://docs.generatepress.com/article/page-hero-background-video/, but I want to not load the video on mobile. I turned the html off on mobile, but according to Google PageSpeed the video is still loading. What is the best way to not load the video on mobile?

    https://fieldofflight.com/

    #2219005
    Ying
    Staff
    Customer Support

    Hi Brenden,

    You can give wp_is_mobile() a try, this is a WP function, for more info:
    https://developer.wordpress.org/reference/functions/wp_is_mobile/

    I would suggest duplicate the current page hero, so there will be 2 elements, 1 with video for desktop and 1 without video for mobile.

    Then you can try this php snippet, replace 100 with the desktop element ID, replace 200with the mobile element ID.

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        if ( (100 === $element_id && wp_is_mobile()) || (200 === $element_id && !wp_is_mobile())  ) { 
            $display = false;
    	}	
        return $display;
    }, 10, 2 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.