Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] An example of a long form implementation of the Theme Customizer.
<?php
function acme_theme_customizer( $wp_customizer ) {
$wp_customizer->add_section(
'acme_header_section',
array(
'title' => __( 'Header Settings', 'acme' ),
'priority' => 200
)
);
$wp_customizer->add_setting(
'acme_header_text_color',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Color_Control(
$wp_customizer,
'acme_header_text_color',
array(
'label' => __( 'Text Color', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_text_color'
)
)
);
$wp_customizer->add_setting(
'acme_header_background_image',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Image_Control(
$wp_customizer,
'acme_header_background_image',
array(
'label' => __( 'Background Image', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_background_image',
)
)
);
$wp_customizer->add_setting(
'acme_header_background_color',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Color_Control(
$wp_customizer,
'acme_header_background_color',
array(
'label' => __( 'Background Color', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_background_color'
)
)
);
} // end acme_theme_customizer
add_action( 'customize_register', 'acme_theme_customizer' );
<?php
function acme_theme_customizer( $wp_customizer ) {
// Header
$wp_customizer->add_section(
'acme_header_section',
array(
'title' => __( 'Header Settings', 'acme' ),
'priority' => 200
)
);
_acme_add_header_color_picker( $wp_customizer );
_acme_add_header_background_color_picker( $wp_customizer );
_acme_add_header_background_image_picker( $wp_customizer );
} // end acme_theme_customizer
add_action( 'customize_register', 'acme_theme_customizer' );
function _acme_add_header_color_picker( $wp_customizer ) {
$wp_customizer->add_setting(
'acme_header_text_color',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Color_Control(
$wp_customizer,
'acme_header_text_color',
array(
'label' => __( 'Text Color', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_text_color'
)
)
);
} // end _acme_add_header_color_picker
function _acme_add_header_background_image_picker( $wp_customizer ) {
$wp_customizer->add_setting(
'acme_header_background_image',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Image_Control(
$wp_customizer,
'acme_header_background_image',
array(
'label' => __( 'Background Image', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_background_image',
)
)
);
} // end _acme_add_header_background_image_picker
function _acme_add_header_background_color_picker( $wp_customizer ) {
$wp_customizer->add_setting(
'acme_header_background_color',
array(
'default' => '',
'transport' => 'postMessage'
)
);
$wp_customizer->add_control(
new WP_Customize_Color_Control(
$wp_customizer,
'acme_header_background_color',
array(
'label' => __( 'Background Color', 'acme' ),
'section' => 'acme_header_section',
'settings' => 'acme_header_background_color'
)
)
);
} // _acme_add_header_background_color_picker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment