Hardcoding Option Tree settings and defaults

Hardcoding Option Tree settings and defaults

The option tree plug in is a brilliant way of setting up extra config data for your theme, but there are some bits of information missing or incorrect from the documentation that is provided with the plugin.

Working with a child theme

It is not immediately obvious, but the instruction for incorporating Option Tree into a theme are for a main, and not a child theme.  When using a childtheme, get_template_directory() should be replaced with get_stylesheet_directory(), e.g.

/**
 * Theme Options
 */
require (get_stylesheet_directory() . '/includes/theme-options.php' );

 Saving the settings without incorporating the plugin

There is a halfway house where the Option Tree Setting and Theme Options can be saved within the theme without incorporating the plugin by generating the theme-options.php and just including that.   The plugin can then be loaded using  TGM Plugin Activation code).

Incorporating defaults involving arrays (e.g. fonts)

The auto-generated theme-options.php file can be modified to incorporate array defaults/standard values as in the following example:

'settings' => array( 
 array(
 'id' => 'cricket_main_heading_font',
 'label' => 'Main Heading Font',
 'desc' => 'Set Color (#660066), Family, Size (20px) and Weight (bold). Set family to \'font-family\' for default. Defaults in brackets',
 'std' => array('font-color' => '#660066','font-size' => '20px','font-weight' => 'bold'),
 'type' => 'typography',
 'section' => 'cricket_colours',
 'rows' => '',
 'post_type' => '',
 'taxonomy' => '',
 'class' => ''
 ),

 


Notice: Undefined index: edit_posts in /home/coherent/thedyers.org.uk/wp-content/plugins/allow-page-authors/allow-page-authors.php on line 389