Add Twinkling Fairy Lights in Divi

Written by Dan Mossop

Why not brighten your Divi theme up this holiday with some festive fairy lights. Here's how to add fairy lights to any Divi section, row or module. Like this:

‘Twas the night before Christmas, when all through the house
Not a creature was stirring, not even a mouse;
The stockings were hung by the chimney with care,
In hopes that St. Nicholas soon would be there;

To achieve this, first add the following PHP code to your site. It's reasonably long, but don't worry – you shouldn't have to modify it in any way:

1if (!function_exists('divibooster_add_fairy_lights_to_section')) {
2
3 function divibooster_add_fairy_lights_to_section($output, $render_slug, $module) {
4
5 if (is_string($output) && isset($module->props['module_class']) && in_array('fairy-lights', explode(' ', $module->props['module_class']))) {
6
7 // Create the fairy lights HTML
8 $fairy_lights = '<div class="fairy-lights-inner" style="">';
9
10 // Cycle through the colors for each light
11 for($i = 0; $i < 100; $i++) {
12 $color = '';
13 switch($i % 4) {
14 case 0 : $color = 'fairy-light-red'; break;
15 case 1 : $color = 'fairy-light-green'; break;
16 case 2 : $color = 'fairy-light-yellow'; break;
17 case 3 : $color = 'fairy-light-blue'; break;
18 }
19 $fairy_lights .= '<span class="' . $color . '"></span>'; // ETModules lightbulb icon
20 }
21 $fairy_lights .= '</div>';
22
23 // Insert our fairy lights HTML just inside the main element
24 $output = preg_replace('/^(<div [^>]*>)/', '$1' . $fairy_lights, $output, 1);
25 }
26
27 return $output;
28 }
29 add_filter('et_module_shortcode_output', 'divibooster_add_fairy_lights_to_section', 10, 3);
30}
31
32if (!function_exists('divibooster_fairy_lights_css')) {
33
34function divibooster_fairy_lights_css() {
35?>
36<style>
37/* Position the fairy lights container */
38.fairy-lights-inner {
39 width: 100%;
40 text-align: center;
41 overflow: hidden;
42 white-space: nowrap;
43 font-size: 24px;
44 line-height: 1;
45 font-family: 'ETModules' !important;
46 position: absolute;
47 top:0;
48 left:0;
49}
50
51/* Style the individual lights */
52.fairy-lights-inner span {
53 transform: scale(.9,1) rotate(180deg);
54 display: inline-block;
55 padding: 20px 10px 0px;
56}
57
58/* Animate the colors */
59.fairy-light-red {
60 color: #D22D2D; /* Classic red color */
61 text-shadow: 0 0 10px rgba(210, 45, 45, 1), 0 0 10px rgba(210, 45, 45, 1), 0 0 10px rgba(210, 45, 45, 1); /* Red glow */
62 animation: twinkle 1.5s infinite alternate;
63}
64
65.fairy-light-green {
66 color: #0F8B0F; /* Traditional green color */
67 text-shadow: 0 0 10px rgba(15, 139, 15, 1), 0 0 10px rgba(15, 139, 15, 1), 0 0 10px rgba(15, 139, 15, 1); /* Green glow */
68 animation: twinkle 1.6s infinite alternate;
69}
70
71.fairy-light-yellow {
72 color: #FFD700; /* Gold color */
73 text-shadow: 0 0 10px rgba(255, 215, 0, 1), 0 0 10px rgba(255, 215, 0, 1), 0 0 10px rgba(255, 215, 0, 1); /* Gold glow */
74 animation: twinkle 1.7s infinite alternate;
75}
76
77.fairy-light-blue {
78 color: #87CEEB; /* Soft blue, akin to silver/blue */
79 text-shadow: 0 0 10px rgba(135, 206, 235, 1), 0 0 10px rgba(135, 206, 235, 1), 0 0 10px rgba(135, 206, 235, 1); /* Soft blue glow */
80 animation: twinkle 1.8s infinite alternate;
81}
82
83@keyframes twinkle {
84 0% { opacity: 0.2; }
85 100% { opacity: 1; }
86}
87
88/* String */
89.fairy-lights-inner span:before {
90 position: absolute;
91 bottom: -5px;
92 content: "";
93 border: 1px solid #999;
94 border-bottom-width: 0;
95 border-left-width: 0;
96 border-radius: 50%;
97 padding: 3px 9px;
98 width: 50%;
99 border-right-width: 0;
100 right: 0%;
101 opacity: 0.5;
102}
103</style>
104<?php
105}
106
107add_action('wp_head', 'divibooster_fairy_lights_css');
108}

Now, on any section, row or module that you want to add fairy lights to, just give it a CSS Class of "fairy-lights", like so: 

Deck Your Divi Site with Holiday Cheer!

Transform your website into a winter wonderland with Divi Christmas Effects. Easily add 7 festive background effects like Falling Snow and Christmas Lights directly into your Divi Builder. No coding needed; just pure holiday magic.

About Dan Mossop

Dan is a Scottish-born web developer, now living in Brisbane with his wife and son. He has been sharing tips and helping users with Divi since 2014. He created Divi Booster, the first Divi plugin, and continues to develop it along with 20+ other Divi plugins. Dan has a PhD in Computer Science, a background in web security and likes a lot of stuff, 

0 Comments

Submit a Comment

Comments are manually moderated and approved at the time they are answered. A preview is shown while pending but may disappear if your are cookies cleared - don't worry though, the comment is still in the queue.

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

We may earn a commission when you visit links on our website.

Latest From Divi Booster

Set Hover Color for Menu Links in the Divi Menu Module

Customizing the hover color of menu links lets you enhance the user experience and maintain visual consistency with your website’s brand. By setting a specific hover color, you can guide visitors' attention and improve navigation feedback. In this guide we show you...

Enable Automatic Looping for YouTube Videos in the Divi Video Module

Enabling automatic looping for YouTube videos in your Divi video module ensures that content plays seamlessly and continuously without interruption. This feature can enhance user engagement, highlight key information, or create dynamic visual effects on your website....

Hide Video Controls in Divi Video Module

Disabling YouTube video controls in the Divi Video Module helps create a seamless, distraction-free viewing experience for your site visitors. This approach is useful when you want full control over how your video content appears and is interacted with on the page, or...

Mute YouTube Videos by Default in the Divi Video Module

In the Divi Video Module, starting your YouTube videos muted by default can create a more user-friendly browsing experience on your webpage. It is particularly beneficial for reducing distractions, enhancing visitor engagement, and providing a seamless content preview...

Autoplay Videos in Divi Video Module

Enabling videos in your Divi video module to start playing automatically can enhance both the site's design and user engagement. To ensure full compatibility with browser requirements, such as Chrome's autoplay policy, it's often necessary to start your videos muted...

Random Divi Posts