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=false){
                $nebula_options = get_option('nebula_options');
    
                if ( empty($nebula_options[$option]) ){
                    if ( !empty($fallback) ){
                        return $fallback;
                    }
    
                    return false;
                }
    
                if ( filter_var($nebula_options[$option], FILTER_VALIDATE_BOOLEAN) === 1 ){
                    return true;
                }
    
                return $nebula_options[$option];
            }
    

    Override

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