How to make custom background color on wordpress?


If it is possible to dynamically change the background color in WordPress. Colors play an important role in how users see your site and how they interact. In this article, we will show you how to randomly change the background color in WordPress.

Method 1: Adding an Arbitrary Background Color Change through Code

In this way, we will add code to our WordPress files. Try this method only if you are comfortable embedding snippets from the web into WordPress.
First you need to add this code to the functions.php file of your theme or plugin for a specific site:
function wpb_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;
}
1
function wpb_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;
}
This function simply generates a random hexadecimal color value and displays.
Now you need to edit the header.php file of your theme. Find the < body > tag  , it will look like this:
<body <?php body_class(); ?>>
1
<body <?php body_class(); ?>>
Now change the line to this:
<body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">>
1
<body <?php body_class(); ?> style="background-color:<?php wpb_bg();?>">>
Save the changes and see what you get:
Randomly changing the background color of the site

Method 2: Adding Random Colors in the Form of Stripes to the Background of the Site Using the Plugin

If you are too lazy to poke around in the code, then the wonderful Fabulous Background Colors plugin will come to your aid. First, install and activate it on your blog. The plugin works out of the box, i.e. a minimum of actions on your part, no need to configure anything.
Now you can visit the site and see the result:
Arbitrary stripes of background color with a plugin
On your website you will see colorful stripes as a background. These bands will fade out and change colors every 5 seconds.

Method 3: Use Css to Add Non-Random Background Colors In Wordpress

Almost all standard WordPress themes support the body_class ( ) function   in the body tag. This tag adds several CSS classes to the body tag in your topic. These default CSS classes created by WordPress can be used to create individual posts, categories, tags, etc.
For example, if your blog has a category called Photos, then you can find these CSS classes in the body tag of the category page.

Add Wordpress CMS Classes

You can override the background color of this particular category by simply adding this CSS to your WordPress theme or using a custom CSS plugin. Paste this code into your CSS:
body.category-photography {
background-color:#faebd7;
}
1
body.category-photography {
background-color:#faebd7;
}
Similarly, you will also find the message identifier class for individual messages in the body class. You can use it to style each WordPress post in different ways.
body.postid-65 {
background-color:#faebd7;
}
1
body.postid-65 {
background-color:#faebd7;
}
This concludes the lesson. I hope this article helped you in solving the questions of how to randomly change the background color of a website on WordPress. Surely you will also be interested in these notes:
How to add smooth background effect in WordPress
How to add a picture background to the entire width of the screen?
How to add fullscreen Youtube video background on WordPress
Have a nice study and see you soon on the blog pages!
For more information visit our website Digital Marketing Services in UAE

Comments

Popular posts from this blog

How to change the url in the wordpress site search form

The Strategies & Successes of Paid Advertising Campaign

Compromising Information in the Fight against Competitors by the Method of Black Pr Campaign