How Randomly Change Background Color in WordPress - WPTRINITY

How Randomly Change Background Color in WordPress

When you want to randomly change background color on your WordPress upon each visit and page reload?
See how to easily do this. First you need to add this code to your theme’s functions.php file.

function wpe_bg() { 
$rand = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
$color ='#'.$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)].
$rand[rand(0,15)].$rand[rand(0,15)].$rand[rand(0,15)];
echo $color;
}

After that , you need to edit the header.php file in your theme. Locate the <body> tag and add replace it with this line:

<body <?php body_class(); ?> style="background-color:<?php wpe_bg();?