Skip to content

Instantly share code, notes, and snippets.

@Arcath
Last active March 29, 2017 10:04
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 Arcath/2257969b108907d295126586f810598e to your computer and use it in GitHub Desktop.
Save Arcath/2257969b108907d295126586f810598e to your computer and use it in GitHub Desktop.
Theme Options Post Code
<?php
$themeOptions = new Arcath\ThemeOptions('theme_slug');
add_action('init', function(){
global $themeOptions;
// Add an option using a custom control class
$themeOptions->addThemeOptionCustomControl('logo_light',
array(
'type' => 'option',
'default' => 0
),
array(
'section' => 'home',
'label' => __('Light Logo', 'theme_slug'),
'description' => __('Light Logo used on darker backgrounds', 'theme_slug'),
),
'WP_Customize_Image_Control'
);
// Add an option with the standard control class
$themeOptions->addThemeOption('phone_number',
array(
'capability' => 'edit_theme_options',
'type' => 'option',
'default' => '0123456789',
),
array(
'label' => 'Phone Number',
'section' => 'home',
'description' => __('Your Phone Number', 'theme_slug')
)
);
});
add_action('customize_register', function($wp_customize){
// Create the required sections
$wp_customize->add_section(
'home',
array(
'title' => 'Home',
'description' => __('Home Page Template options.', 'theme_slug'),
'capability' => 'edit_theme_options',
)
);
});
?>
<?php
global $themeOptions;
echo($themeOptions->themeOption('phone_number'));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment