Hello,
At the moment I’m trying to work with wordpress built in Customizer, For som reason i cant get the live preview to work, don’t know if it is because i have made something wrong… But simply written this code:
function tcx_register_theme_customizer( $wp_customize ) {
$wp_customize->add_setting(
‘tcx_link_color’,
array(
‘default’ => ‘#000000’,
‘transport’ => ‘postMessage’
)
);
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
‘link_color’,
array(
‘label’ => __( ‘Link Color’, ‘tcx’ ),
‘section’ => ‘colors’,
‘settings’ => ‘tcx_link_color’
)
)
);
}
add_action( ‘customize_register’, ‘tcx_register_theme_customizer’ );
function tcx_customizer_css() {
a { color: <?php echo get_theme_mod( 'tcx_link_color' ); ?>; } <?php } add_action( 'wp_head', 'tcx_customizer_css' );
?>
function tcx_customizer_live_preview() {
wp_enqueue_script(
‘tcx-theme-customizer’,
get_template_directory_uri() . ‘assets/js/theme-customizer.js’,
array( ‘jquery’, ‘customize-preview’ ),
‘0.3.0’,
true
);
} // end tcx_customizer_live_preview
add_action( ‘customize_preview_init’, ‘tcx_customizer_live_preview’ );
With the fallowing JS file:
(function( $ ) {
“use strict”;
wp.customize( ‘tcx_link_color’, function( value ) {
value.bind( function( to ) {
$( ‘head a’ ).css( ‘color’, to );
} );
});
})( jQuery );
And for some reason it works perfectly to save here, but the live preview doesn’t work…
If some one is able to guide me how to use The customizer in wordpress together with ROOTS that would be amazing!
Best,
Max