Skip to content

Instantly share code, notes, and snippets.

@sudipbd
Created November 19, 2016 08:26
Show Gist options
  • Save sudipbd/706c7aef055cc2a1186b3a17776d2f11 to your computer and use it in GitHub Desktop.
Save sudipbd/706c7aef055cc2a1186b3a17776d2f11 to your computer and use it in GitHub Desktop.
WordPress Option Tree setup for theme option
<?php
//option tree setup for theme option
//first download option tree plugin from wordpress.org then paste the folder in theme directory.
//copy 2 files “theme-options.php” and “meta-boxes.php” to inc folder then include.
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
include_once( 'option-tree/ot-loader.php' );
include_once( 'inc/theme-options.php' );
//Custom Meta Box
include_once('inc/v-meta-boxes.php');
?>
//finally calling it from header.php
<a href="<?php echo esc_url( home_url( '/' ) ); ?>">
<?php $logo = get_option_tree( 'logo', '', false ); ?>
<?php if($logo) : ?>
<img src="<?php echo $logo;?>"/>
<?php else : ?>
<img src="<?php echo get_template_directory_uri()?>/img/e24logo.png ?>" alt="">
<?php endif; ?>
</a>
//adding logo option
//adding a section on theme-options.php
'sections' => array(
array(
'id' => 'header',
'title' => __( 'Logo', 'e24' )
)
),
//adding the settings for it
'settings' => array(
array(
'label' => 'Upload The Logo.',
'id' => 'logo',
'type' => 'upload',
'section' => 'header',
'desc' => 'Upload your logo here. Recommended logo size is 125x40. However, if you want to insert bigger size, no problem, just maintain the ratio. So if you want a 2x logo insert 250x80, if you want a 4x logo insert 500x160.'
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment