Created
May 13, 2017 13:06
-
-
Save Jonnyauk/bcf44d74302e16b55a6f535289be3280 to your computer and use it in GitHub Desktop.
Customizer functionality example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customizer functionality example | |
*/ | |
/** | |
* | |
* We include all panels, settings and controls in this one function | |
* | |
*/ | |
function mytheme_customizer_do( $wp_customize ) { | |
// Add setting to save | |
$wp_customize->add_setting( 'opt_link_colour', array( | |
'default' => '#00a9ac', | |
'transport' => 'postMessage' | |
) ); | |
// Add setting to save | |
$wp_customize->add_setting( 'opt_strapline', array( | |
'default' => 'Now we are getting cute!', | |
'transport' => 'postMessage' | |
) ); | |
// Add panel | |
$wp_customize->add_panel( 'theme_panel_1', array( | |
'title' => 'My Theme Options', | |
'description' => 'Here is my description, I can help users!', | |
'capability' => 'edit_theme_options', | |
'priority' => 10 | |
) ); | |
// Add section to group options | |
$wp_customize->add_section( 'section_colours', array( | |
'title' => 'My Colors', | |
'panel' => 'theme_panel_1', | |
'priority' => 10 | |
) ); | |
// Add section to group options | |
$wp_customize->add_section( 'section_text', array( | |
'title' => 'My Text', | |
'panel' => 'theme_panel_1', | |
'priority' => 20 | |
) ); | |
// Add control | |
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_colour', array( | |
'label' => 'Link Color', | |
'section' => 'section_colours', | |
'settings' => 'opt_link_colour' | |
) ) ); | |
// Add control | |
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'strapline', array( | |
'label' => 'Header strapline', | |
'section' => 'section_text', | |
'settings' => 'opt_strapline' | |
) ) ); | |
// Now make core controls refresh with JS too! | |
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; | |
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; | |
} | |
add_action( 'customize_register', 'mytheme_customizer_do' ); | |
/** | |
* | |
* Inserts Customizer link colour option 'opt_link_colour' | |
* | |
*/ | |
function mytheme_do_opt_link_colour() { | |
?> | |
<style type="text/css"> | |
a { color: <?php echo sanitize_hex_color(get_theme_mod('opt_link_colour', '#00a9ac')); ?>; } | |
</style> | |
<?php | |
} | |
add_action( 'wp_head', 'mytheme_do_opt_link_colour'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment