006_TF_Getting-Option-ValuesGetting options is easy and done with a single function call:

Always use the code above inside WordPress hooks that run on or after after_setup_theme For example:

For meta box options, you can optionally include a post ID of a page or post to get their values (can be helpful when creating your own post loops). This is optional, if no post ID is given, the post ID of the current loop will be used:

The value type that you get may differ depending on the option’s type. For example, a text option returns a string; a select-googlefont option returns an array containing data of the selected font.

The Do’s & Don’ts

  1. DO use getOption inside the after_setup_theme WordPress hook. Any other hooks that run after it are also acceptable – e.g. admin_init, wp_head, wp_enqueue_scriptsDO use getOption straight from your theme’s template files – e.g. single.php, index.php, archive.php.
  2. DO use getOption straight from your theme’s template files – e.g. single.php, index.php, archive.php.
  3. DON’T use getOption directly from your functions.php outside a hook (or any non-template script without a hook for that matter). Doing so will give out errors since Titan Framework has not initialized yet.
  4. DON’T use getOption directly from your functions.php outside a hook (or any non-template script without a hook for that matter). Doing so will give out errors since Titan Framework has not initialized yet.


Some Notes

[zilla_alert]Before version v1.2.2, the postID was required.[/zilla_alert]

2 thoughts

    1. Currently you can do this through default values. An undocumented way right now (which we’ll later add) is setOption.

Leave a Reply