0

on my site I'm using cenetric, a child theme of genesis and this theme comes with some predefined color schemes.

//* Add support for additional color style options
add_theme_support( 'genesis-style-selector', array(
    'centric-pro-charcoal' => __( 'Centric Charcoal', 'centric' ),
    'centric-pro-green'    => __( 'Centric Green', 'centric' ),
    'centric-pro-orange'   => __( 'Centric Orange', 'centric' ),
    'centric-pro-purple'   => __( 'Centric Purple', 'centric' ),
    'centric-pro-red'      => __( 'Centric Red', 'centric' ),
    'centric-pro-yellow'   => __( 'Centric Yellow', 'centric' ),
) );

Now I am looking for a way to create a random color scheme, so that every time any user visit my site, the color scheme gets automatically selected. I've tried the following:

$thm_out = array("Charcoal", "Green", "Orange", "Purple", "Red", "Yellow");

//* Add support for additional color style options
add_theme_support( 'genesis-style-selector', array(
    'centric-pro-charcoal' => __( 'Centric Charcoal', 'centric' ),
    'centric-pro-green'    => __( 'Centric Green', 'centric' ),
    'centric-pro-orange'   => __( 'Centric Orange', 'centric' ),
    'centric-pro-purple'   => __( 'Centric Purple', 'centric' ),
    'centric-pro-red'      => __( 'Centric Red', 'centric' ),
    'centric-pro-yellow'   => __( 'Centric Yellow', 'centric' ),
    'centric-pro-random'   => __( 'Centric '.$thm_out[array_rand($thm_out, 2)].'', 'centric' ),
) );

But its giving the following error in my admin panel and also not working properly.

Warning: Illegal offset type in C:\xampp\htdocs\dev\wp-content\themes\centric-pro\functions.php on line 69

So, can you guys please help me to fix this issue?

1

This:

$thm_out[array_rand($thm_out, 2)]

is the same as

$them_out[array(0,2)] where 0 and 2 are 2 random keys.

See array_rand

I hope you can see what is wrong there. Change that to:

$thm_out[array_rand($thm_out, 1)]

which is the same as

$them_out[2] where 2 is any random key.

  • but it keep selecting the 1st element of the array. How to fix that? – iSaumya Mar 1 '15 at 13:45

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.