Here is the code I'm using to add the section to the Customize Panel.
function apple_customize_register($wp_customize){
$wp_customize->add_section('apple_footer', array(
'title' => 'Footer',
'priority' => 120,
));
//------ display copyright in footer
$wp_customize->add_setting('theme_options[copyright]', array(
'capability' => 'edit_theme_options',
'type' => 'option',
));
$wp_customize->add_control('theme_options[copyright]', array(
'settings' => 'theme_options[copyright]',
'label' => __('Display Copyright'),
'section' => 'apple_footer',
'type' => 'checkbox',
'value' => '1'
));
}
add_action('customize_register', 'apple_customize_register');
I have tried get_option('theme_options[copyright]'), get_theme_mod('theme_options[copyright]') and many more, but all var_dump are returning bool(false).
How do I use the values in my theme?
That's because [copyright] is one of the values of an Array.
Get the theme options with get_option('theme_options'); And inside the result you'll find 'copyright'.
$options = get_option('theme_options');
echo $options['copyright'];
This is how you store a big number of options inside a single record in the database (the recommended way). If you visit the page http://example.com/wp-admin/options.php, you'll see all records in wp_options table. Some plugins and themes use one record per option, the result is not pretty.
If you add another control to the Customizer, register as theme_options['OTHER_CUSTOM_SETTING']. Remember to change theme_options for your theme's slug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With