• Resolved sgrx

    (@sgrx)


    I have a page with id 40 which shouldn’t display the Jetpack’s mobile theme on smartphones, while all other pages should. How do I do this?

    I found this filter but maybe I’m using it incorrectly, or it doesn’t work in my functions.php:

    
    // define the jetpack_check_mobile callback 
    function filter_jetpack_check_mobile( $is_mobile ) { 
        if(is_page(40))
        {
            $is_mobile = false;
        }
        return $is_mobile; 
    };        
    // add the filter 
    add_filter( 'jetpack_check_mobile', 'filter_jetpack_check_mobile', 10, 1 );
    • This topic was modified 9 years, 2 months ago by sgrx.
Viewing 3 replies - 1 through 3 (of 3 total)
  • jetpack_check_mobile function checks whether the reader is on a mobile device or not. You may need to use jetpack_mobile_exclude function, but it doesn’t have any hook to add your own page.
    https://github.com/Automattic/jetpack/blob/4.9/modules/minileven/minileven.php/#L56-L77

    Someone from Jetpack team will respond here soon.

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    I’m not sure there is an easy way around this. By the time you know what page you’re on, and consequently can use conditional tags like is_page( 40 ), the stylesheets are already loaded. You could hook into the page later, with a hook like template_redirect, and then simply remove the filters where Jetpack overwrites the template and the stylesheet (see here), but I’m afraid by that time the stylesheets are already enqueued and it’s going to be too late.

    Another approach would be to use the akm_mobile cookie set by Jetpack’s Mobile Theme, and set it to reject mobile (false) on specific pages (see here), but you would then have to set it to true on the other pages.

    I hope this helps a bit.

    Thread Starter sgrx

    (@sgrx)

    Thanks @jeherve. I was getting inconsistent results with setting the cookie but I will work on it more and try again.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Disable mobile theme only for one page’ is closed to new replies.