One of Diviβs main goals is to make sure that every element on your website looks good, and blog posts are no exception. However, thereβs always room for improvement, and color coding your blog posts by author offers a way for users to navigateΒ your content more efficiently (as well as identifying their favorite writers!).
In this article, weβre going to talk more about why you may want to color code your Divi blog posts, and how to do it in two simple steps. Itβs time for a new coat of paint!
Why You Should Consider Color Coding Your Divi Blog Posts
Before we go any further, letβs clear up what we mean by color coding your Divi blog posts. In the next section, weβre going to teach you how to assign each of your writers a color that will appear as the background for their own posts. In this example, I assigned my own posts (as author1) a very fetching light blue:
The effect itself is relatively simple, but it offers an impactful way to differentiate writers. Users can easily recognize new pieces by their favorite writers at a glance. Of course, making the authorβs name more prominent may have the same effect, but it may not beΒ as visually striking.
Your only concern with this is your choice ofΒ colors. Take the screenshot at the beginning of this section for example β our Divi blog index uses a white background, so we decided to stick with light pastel colors for our authorsβ posts. Letβs seeΒ what happens if we chooseΒ a different color scheme:
Of course, thatβs an extreme example, but it helps us illustrate our point. If you want to color code your posts, youβll need to consider your palette carefully, using a suitable tool to help if necessary. Using contrasting colors to highlight the difference between each post can help users identify authors quickly, but it can also play havoc with your blogβs style and make it hard to read your content.
Now weβve covered the theory, itβs time to move onto how to actually color code Divi blog posts. Enabling this feature only takes two steps, but there are some considerations to make before beginning.
For starters, youβll want to back up your WordPress site, which is always a good idea when making changes. Secondly, youβll want to create a Divi child theme, so your modifications willΒ remain once the theme is updated.
Finally, youβll need to use an FTP client for step number one. Weβll be using FileZilla,Β but if thereβs another tool you prefer, go for it.
Step #1: Add a Code Snippet to Your Child Themeβs functions.php file
To do this, youβll need to open your FTP client and log into your siteβs server. From there, head to the public_html/wp-content/themes/ directory, then find your child themeβs folder. Keep in mind, the public_html or root folder may beΒ named www or after your siteβs domain, depending on your host:
Once youβve located your child themeβs folder, open it and look for the functions.php file within. Now, right-click on it and hit the option that reads View/Edit:
This will prompt you to open the file with your default text editor. Since weβre dealing with a child theme, your functions.php file should be mostly bare aside from enqueuing its parentβs functions. Weβre going to add a snippet that automatically creates a new class for each of your authors with the author- prefix. For example, if you have a WordPress user named John, you could use the author-john class.Β This will enable us to add some CSS code later on.
Next,Β add the following PHP snippet after the // END ENQUEUE PARENT ACTION line:
function et_set_author_class( $classes ) {$classes[] = 'author-' . strtolower( str_replace( ' ', '-', get_the_author() ) ); return $classes;} add_filter( 'post_class', 'et_set_author_class' );
Now save your changes, close the editor, and youβre done! Keep in mind youβll need to use lowercase characters for your class to work, regardless of which author youβre dealing with. Thatβs going to be important for step number two.
Now our new function is ready, the next step is toΒ set a color for each of your authors. Divi enables you to do this with its Custom CSS feature, since any code you add there will affect your entire theme. To find it, go to your WordPress dashboard and navigate toΒ the Divi > Theme Options tab, then scroll down to the Custom CSS box at end of the page:
Youβll need to add a new line of CSS within this field for each of your authors. For example, if you have an author with the username author1 hereβs how youβd set a particular color for them:
.author-author1 {background-color: #C1F3FA !important;}
Keep in mind you need to add the author- prefix to your class, regardless of your username. After indicating a background color, you also need to make sure to declare the code is !important. Simply put, this gives the code more weight and overrides any conflicts that might arise β without it, this feature wonβt work.
Letβs go over one last example. In this, weβllΒ assign different colors to two authors. Hereβs the code we added to our Divi custom CSS field:
.author-author1 {background-color: #C1F3FA !important;} .author-author2 {background-color: #F9FCB8 !important;}
Now, hereβs what that looks like from the front end:
Putting aside your choice of color, there are other tweaks you can make to your Divi blog posts. For example, you can tweak the length of your blog excerpts or style your post βcardsβ in multiple ways. Your main goal should be to find the perfect style for your own blog, so donβt be afraid to play around with Divi and see what it can do!
Conclusion
Color coding your blog posts by their author is a simple feature that can help the user navigate your content much more easilyΒ (particularly if you have an extensive archive). Plus, a lot of your users will probably appreciate being able to recognize their favorite authorβs posts by color alone.
Before you start tweaking files, remember to back up your site and set up a child theme, so your changes will persist in the future. Once thatβs done, these are the two steps you need to follow to color code your Divi blog posts by author:
- Modify your child themeβs functions.php file.
- Specify a color for each of your authors using Diviβs custom CSS option.
Do you have any questions about how to color code Divi blog posts by author? Ask away in the comments section below!
Article thumbnail image by RaZZers / shutterstock.com.
Very nice set, thank you!
You’re welcome; thanks for your comment. π
This is great! I was wondering about such a idea for a while! Thank you!
You’re welcome, Jordan! π
Nice! Is this easy to tweak to be used for color coding based on post categories?
Thanks for commenting, Marcel! Check out our response to Eric above. π
Same here: I would very much like to see a tut on how to color code by post category.
Hi Eric; check out our forums (https://www.elegantthemes.com/forum/) to see if any other users have advice on how to do that. π
Thanks – a tutorial on how to color code by post category would be awesome!
If you look at the DOM Structure of the Blog Module you will notice a category-specific css class is already there … use it to style the article elements π
Pascal,
damn, you’re absolutely right! Never checked that, maybe expecting it to be part of some Divi setting. But I can see that categories get the style prefix ‘category-‘ and even tags have a prefix ‘tag-‘.
Gonna use it right away in an upcoming project, was looking for this.
Thanks for your input, very helpful.
How would you do this with categories instead of authors?
Hi Anita! The process would be similar, but would likely require a few tweaks. We’d recommend checking out the forums (https://www.elegantthemes.com/forum/) to see if another user can help out.
+1 Both great ideas!
Yes that would be awesome.