Skip to Content
Menu

get_option()

Check for theme options set on the Appearance > Nebula Options page in the WordPress admin.

PHP June 20, 2017

Usage

PHP
nebula()->get_option($option, $fallback)

Parameters

$option
(Required) (String) The name of the option.
Default: None

$fallback
(Optional) (String) The data to use if the option is not set or false.
Default: false

Parameter Notes

For a list of core Nebula option names, refer to the default_options documentation.

Request or provide clarification »

Examples

Echo a string-based option.

PHP
<?php echo nebula()->option('ga_tracking_id'); ?>

String-based with a default if false.

PHP
<?php echo nebula()->option('fax_number', 'No fax number'); ?>

Check if a boolean option is enabled.

PHP
if ( nebula()->option('scss') ){
     //Do something if Sass is enabled.
}

Check if a boolean option is disabled.

PHP
if ( !nebula()->option('scss') ){
    //Do something if Sass is disabled
}
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/Options/Options.php on line 46.

    No Hooks

    This function does not have any filters or actions available. Request one?
    PHP
            public function get_option($option, $fallback=null){
                $nebula_options = get_option('nebula_options');
    
                //Always return the exact, unfiltered value for WP-CLI
                if ( $this->is_cli() ){
                    return $nebula_options[$option];
                }
    
                //If the value is not set or false, return the provided fallback value
                if ( empty($nebula_options[$option]) ){
                    return $fallback;
                }
    
                //Normalize boolean-like strings/numbers to bool type
                $boolean_value = filter_var($nebula_options[$option], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
                if ( $boolean_value !== null ){ //This means it is a boolean value of true or false
                    return $boolean_value;
                }
    
                return $nebula_options[$option];
            }
    

    Override

    This function can not be short-circuited with an override filter. Request one?