Randomize Predefined Colors for WordPress Theme Element

Just put this into functions.php of your child theme with the needed CSS selector. Add your desired colors to colors array.

// random headers for title
function random_bg() { ?>
<style>
<?php
$input = array("#5F9EA0", ""#a0795f", "#9ca05f", "#73a05f");
$rand_key = array_rand($input);
$color = $input[$rand_key];
?>
.page-item-title h1 {
background-color: <?php echo $color; ?>;
}
?>
</style>
<?php }
add_action( 'wp_head', 'random_bg' );

The style declaration will be added into head of the page.

Share:
This entry was posted in WordPress and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *