Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created May 7, 2012 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dongilbert/2627998 to your computer and use it in GitHub Desktop.
Save dongilbert/2627998 to your computer and use it in GitHub Desktop.
Helper functions for WP Option Tree
<?php
/**
* Paste this code in your theme's functions.php
* file and wherever you normally would call
* `get_option_tree('option-name');`, use
* `get_theme_option('option-name');` instead.
* This will pass through the already retrieved
* global $option_tree (called when your theme loads)
* and save you from several additional database
* calls on a single page request.
*
* Update: I created a shortcode to access the
* settings within a post/page.
* https://gist.github.com/2870164
*/
if(function_exists('get_option_tree'))
{
global $option_tree;
$option_tree = get_option('option_tree');
function theme_option($id)
{
echo get_theme_option($id);
}
function get_theme_option($id)
{
global $option_tree;
return get_option_tree($id, $option_tree);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment