The solutions in this tutorial enable you to change the background color, not background image, based on the category the post is assigned to.
In this tutorial, you’ll get 2 code snippets which enable you to change the background color :
- Using pure PHP code
- Using ACF with PHP code
The 2nd solution requires changing the background color via the edit category admin screen :
There are other ways to do this using PHP, jQuery or CSS however these 2 are amongst the most efficient methods.
Note : You can also use this code to change the background color based on any conditionals simply by changing the conditional tags.
Firstly, lets take a look at a video which shows you exactly what the code in this tutorial enables you to do.
The video shows how you can set a default background color using the customizer which you can change on any category archive page. You can also set a default for the category page and posts in the same category if none added.
Here’s the code snippets for registered users :