What I'm doing

User interface to change website colors - User can change colors individually (like menu color, footer color, content color), or use color scheme that will change all colors (values pre-defined by me)

The Problem

$color_menu, $color_footer and $color_content already work individually

I need to set the color_scheme now, I tried this, but didn't work:

<?php $color_menu = get_option('color_menu');  ?>
<?php $color_footer = get_option('color_footer ');  ?>
<?php $color_content = get_option('color_content ');  ?>

    if ( get_option( $color_scheme ) == 'blue' ) {
        update_option( $color_menu, '#0D5E84' );
        update_option( $color_footer, '#1461A2' );
        update_option( $color_content, '#132C3F' );
    } elseif ( get_option( $color_scheme ) == 'yellow' ) {
        update_option( $color_menu, '#CCCC00' );
        update_option( $color_footer, '#FFFF33' );
        update_option( $color_content, '#FFFFCC' );
    } elseif ( get_option( $color_scheme ) == 'red' ) {
        update_option( $color_menu, '#CC0000' );
        update_option( $color_footer, '#FF0000' );
        update_option( $color_content, '#CC0033' );
    } else {
        update_option( $color_menu, '#252525' );
        update_option( $color_footer, '#252525' );
        update_option( $color_content, '#FFFFFF' );

Image: https://i.sstatic.net/Ktm7h.png

Extra problem

Be able to change individual colors while using Color Scheme.

Let's suppose I chose a Yellow color scheme, but would like to set the menu color darker, I should be able to change it while using Yellow color scheme, if possible

Another Point of View

A friend that works with me thought of a different solution for this same problem, and he posted it on Stack Overflow, maybe you would like to see his question.

Easier to do? Better? Worse? What path shoud we go?

1 Answer 1


Don't save everything as individual options, save all of your options as an array under a single key. One query to load it and save it, then just do all your manipulation in php.

example structure and output:

$colors = array(
    'current_scheme' => 'user_scheme',
    'preset_schemes' => array(
        'red' => array(
            'menu' => '#CC0000',
            'footer' => '#FF0000',
            'content' => '#CC0033'
    'user_scheme' => array(
        'menu' => 'red',
        'footer' => 'red',
        'content' => '#132C3F' // override with custom color
update_option( 'prefix_theme_options', $colors );

foreach( $colors['user_scheme'] as $location => $value ):
    echo $location . ': ';
    if( array_key_exists( $value, $colors['preset_schemes'] ) ):
        echo $colors['preset_schemes'][$value][$location];
        echo $colors['user_scheme'][$location];
    echo '<br>';
  • Hello @Milo! This function has been made thinking on the end-user, so there can't be any php programming or stuff to change individual colors, I didn't understand quite right your approach to the problem, are you using color scheme only? Commented Mar 9, 2013 at 13:19
  • It is crutial for the customer to be able to change the colors individually. We are trying to add color scheme just to make it easier to them =) Commented Mar 9, 2013 at 13:26
  • the array contains your preset schemes, then the user scheme contains either their custom color or a reference to a preset scheme. obviously some amount of php is necessary to convert their selections into an option you can save in the database, regardless of how you save it. whether or not you use this specific structure, the overall point is don't save a bunch of individual options, it's less efficient to load/save, and just litters the database with extra data to clean up later.
    – Milo
    Commented Mar 9, 2013 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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