Skip to Content
Menu

is_desktop()

Check if the user’s device is a desktop computer.

PHP April 1, 2021

Usage

PHP
nebula()->is_desktop()

Parameters

This function does not accept any parameters. Is this incorrect?

Was this page helpful? Yes No


    A feedback message is required to submit this form.


    Please check that you have entered a valid email address.

    Enter your email address if you would like a response.

    Thank you for your feedback!

    Source File

    Located in /libs/Utilities/Device.php on line 30.

    1 Hook

    Find these filters and actions in the source code below to hook into them. Use do_action() and add_filter() in your functions file or plugin.

    Filters
    "pre_nebula_is_desktop"
    Need a new filter hook? Request one here.

    Actions
    This function has no action hooks available. Request one?

    PHP
            public function is_desktop(){
                $override = apply_filters('pre_nebula_is_desktop', null);
                if ( isset($override) ){return $override;}
    
                if ( !wp_is_mobile() ){ //This does a basic check for mobile or tablet devices.
                    return true;
                }
    
                //Check User Agent Client Hints
                if ( isset($_SERVER['HTTP_SEC_CH_UA_MOBILE']) && $_SERVER['HTTP_SEC_CH_UA_MOBILE'] === '?0' ){ //if Sec-CH-UA-Mobile client hint is ?0
                    return true;
                }
    
                return false;
            }
    

    Override

    To override this PHP function, use this hook in your child theme or plugin ("my_custom" can be changed):

    PHP
    add_filter('pre_nebula_is_desktop', 'my_custom_is_desktop'); 
    function my_custom_is_desktop(){ 
        //Write your own code here
    
        return true; //Return true to prevent the original function from running afterwords
    }

    You can completely disable this PHP function with a single line actions:

    PHP
     add_filter('pre_nebula_is_desktop', '__return_false');