I'm looking to create a color picker in the admin for the anchors. I know it can be done by CSS but I have a multisite and would like users to easily set the link colors.

The following works but there is a delay for the color to show unlike the color picker for the background color, so I'm just checking if the following can be improved:

function tcx_register_theme_customizer( $wp_customize ) {
       // 'default'     => '#ff0000'
    new WP_Customize_Color_Control(
            'label'      => __( 'Link Color', 'tcx' ),
            'section'    => 'colors',
            'settings'   => 'tcx_link_color' 
    add_action( 'customize_register', 'tcx_register_theme_customizer' );

    function tcx_customizer_css() {
    <style type="text/css">
        a { color: <?php echo get_theme_mod( 'tcx_link_color' ); ?>; }
    add_action( 'wp_head', 'tcx_customizer_css' );

Any help appreciated

1 Answer 1


Create customizer.js file and put the following script in the customizer.js file

(function( $ ) {
    "use strict";   
    wp.customize( 'tcx_link_color', function( value ) {
        value.bind( function( to ) {
            $( 'a' ).css( 'color', to );
        } );
})( jQuery );

And enqueue your customizer.js file by using wp_enqueue_script in your customizer.php file like this

function tcx_customizer_script() {
        get_template_directory_uri() . '/js/customizer.js',
        array( 'jquery', 'customize-preview' ),
add_action( 'customize_preview_init', 'tcx_customizer_script' );

Then it work fine


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.