Skip to content

Instantly share code, notes, and snippets.

@papacasper
Forked from danielpataki/add-section.php
Last active June 4, 2019 17:48
Show Gist options
  • Save papacasper/4249ba15f3936a531ffd157e4f61a070 to your computer and use it in GitHub Desktop.
Save papacasper/4249ba15f3936a531ffd157e4f61a070 to your computer and use it in GitHub Desktop.
Customizer Tutorial
$wp_customize->add_section( 'cd_colors' , array(
'title' => 'Colors',
'priority' => 30,
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_color', array(
'label' => 'Background Color',
'section' => 'cd_colors',
'settings' => 'background_color',
) ) );
$wp_customize->add_setting( 'background_color' , array(
'default' => '#43C6E4',
'transport' => 'refresh',
) );
add_action( 'wp_head', 'cd_customizer_css');
function cd_customizer_css()
{
?>
<style type="text/css">
body { background: #<?php echo get_theme_mod('background_color', '#43C6E4'); ?>; }
</style>
<?php
}
( function( $ ) {
} )( jQuery );
add_action( 'customize_register', 'cd_customizer_settings' );
function cd_customizer_settings( $wp_customize ) {
}
( function( $ ) {
wp.customize( 'background_color', function( value ) {
value.bind( function( newval ) {
$( 'body' ).css( 'background-color', newval );
} );
} );
} )( jQuery );
add_action( 'customize_preview_init', 'cd_customizer' );
function cd_customizer() {
wp_enqueue_script(
'cd_customizer',
get_template_directory_uri() . '/customizer.js',
array( 'jquery','customize-preview' ),
'',
true
);
}
include('customizer.php');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment