Theme Options: Get an Option Value

Function Reference: themeblvd_get_option

This function will retrieve a setting saved from Appearance > Theme Options of the Theme Blvd framework. It’s designed to work similarly to WordPress’s get_option. However it’s not exactly the same; so, make sure to have a look at the parameters outlined below.

Also, note that the entire theme options page’s settings array is retrieved and stored at runtime, and so by using this function, you’re accessing that opposed to pulling from your database every time you want to retrieve a single option.

If you’re looking to pull the value for an option already in your theme, and you’re trying to figure out the option ID, see Finding Default Option Attributes.

Note: The framework doesn’t initialize the theme settings until “wp” action in the WordPress loading process. So, themeblvd_get_option() cannot be used to retrieve a value until after this point.
$val = themeblvd_get_option( $primary, $secondary, $default );
(string) (required) This is the ID of the option.
Default: None
(string) (optional) If retrieving an array, you can pass the key directly within an option. This won't be used in most cases.
Default: None
(string) (optional) This will override the theme's default value for the option, if it's never been saved.
Default: None
Note: Originally, the $default parameter wasn’t working properly. — If an option were empty, but the rest of the theme options page had been saved, it would not return this default value you passed in. This was fixed in framework v2.6.1.

In this example we’ll retrieve and print the footer copyright option, which is just a simple text field input on the Theme Options page.

echo themeblvd_get_option('footer_copyright');

Now, we’ll add in a default value. The theme will already have a default value for the option, but by specifying one here, we can override that, in the event the value were empty.

echo themeblvd_get_option('footer_copyright', '', 'This is our default value');

How to Get Option Value Before “WP” Action

One snafu you may run into is trying to retrieve an option’s value earlier than the “wp” action of WordPress.

In the following example, I’m hooking to after_setup_theme to setup some functionality, where I’ll need values from the theme options page. Since I know this action comes before wp action, themeblvd_get_option() won’t be available yet. — For more on the order of how WordPress loads core actions, see Plugin API/Action Reference.

function my_something_cool() {

    $settings = get_option( themeblvd_get_option_name() );

    $foo = $settings['foo'];
    $bar = $settings['bar'];

    //  Continue on ...

add_action('after_setup_theme', 'my_something_cool');