Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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 enable_theme_customization__acme( $wp_customizer ) {
$wp_customizer->add_section(
'header_section__acme',
array(
'title' => __( 'Header Settings', 'acme' ),
'priority' => 200
)
);
allow_customization_of__acme(
__( 'Text Color', 'acme' ),
$which_is_a = 'Color',
$and_call_it = 'header_text_color__acme',
$wp_customizer
);
allow_customization_of__acme(
__( 'Background Image', 'acme' ),
$which_is_an = 'Image',
$and_call_it = 'header_background_image__acme',
$wp_customizer
);
allow_customization_of__acme(
__( 'Background Color', 'acme' ),
$which_is_a = 'Color',
$and_call_it = 'header_background_color__acme',
$wp_customizer
);
} add_action( 'customize_register', 'enable_theme_customization__acme' );
function allow_customization_of__acme( $label, $option_type, $option_id, $wp_customizer ) {
$wp_customizer->add_setting(
$option_id,
array(
'default' => '',
'transport' => 'postMessage'
)
);
$control_class_name = "WP_Customize_{$option_type}_Control";
$wp_customizer->add_control(
new $control_class_name(
$wp_customizer,
$option_id,
array(
'label' => $label,
'section' => 'header_section__acme',
'settings' => $option_id
)
)
);
}
<?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
You can’t perform that action at this time.