Home » Php » My color picker in WordPress's 2016 theme doesn't connect to menu text, how do I fix it?

My color picker in WordPress's 2016 theme doesn't connect to menu text, how do I fix it?

Posted by: admin September 25, 2018 Leave a comment

Questions:

I’m currently editing the 2016 WordPress theme (Version 1.5) for a school project and I want to add more color pickers. From my code below, my color picker comes up in the Customizer but whenever I try to change the color of my navigation menu text, it comes up gray instead of blue or red. How can I fix this?

Side note: I’ve omitted the other color pickers that were in the theme already just to save space.

/*This is the code that I added in color-scheme-control.js*/
( function( api ) {
var cssTemplate = wp.template( 'twentysixteen-color-scheme' ),
    colorSchemeKeys = [
        'menu_text_color' 
    ],
    colorSettings = [
        'menu_text_color' 
    ];
api.controlConstructor.select = api.Control.extend( {
    ready: function() {
        if ( 'color_scheme' === this.id ) {
            this.setting.bind( 'change', function( value ) {
                var colors = colorScheme[value].colors;
                // Update Header Menu Text Color.
                color = colors[5];
                api( 'menu_text_color' ).set( color );
                api.control( 'menu_text_color' ).container.find( '.color-picker-hex' )
                    .data( 'data-default-color', color )
                    .wpColorPicker( 'defaultColor', color );
            } );
        }
    }
} );`

/*in the customizer.php*/
return <<< CSS
/* Menu Text Color */
.main-navigation a{
    color: {$colors['menu_text_color']}; 
}`
Answers: