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:

if (!function_exists('divibooster_add_fairy_lights_to_section')) {
	
	function divibooster_add_fairy_lights_to_section($output, $render_slug, $module) {
		
		if (is_string($output) && isset($module->props['module_class']) && in_array('fairy-lights', explode(' ', $module->props['module_class']))) {
			
			// Create the fairy lights HTML
			$fairy_lights = '<div class="fairy-lights-inner" style="">';
			
			// Cycle through the colors for each light
			for($i = 0; $i < 100; $i++) { 
				$color = '';
				switch($i % 4) {
					case 0 : $color = 'fairy-light-red'; break;
					case 1 : $color = 'fairy-light-green'; break;
					case 2 : $color = 'fairy-light-yellow'; break;
					case 3 : $color = 'fairy-light-blue'; break;
				}
				$fairy_lights .= '<span class="' . $color . '"></span>'; // ETModules lightbulb icon
			}
			$fairy_lights .= '</div>';

			// Insert our fairy lights HTML just inside the main element
			$output = preg_replace('/^(<div [^>]*>)/', '$1' . $fairy_lights, $output, 1);
		}

		return $output;
	}
	add_filter('et_module_shortcode_output', 'divibooster_add_fairy_lights_to_section', 10, 3);
}

if (!function_exists('divibooster_fairy_lights_css')) {

function divibooster_fairy_lights_css() {
?>
<style>
/* Position the fairy lights container */
.fairy-lights-inner {
	width: 100%;
  	text-align: center;
  	overflow: hidden;
  	white-space: nowrap;
  	font-size: 24px;
  	line-height: 1;
	font-family: 'ETModules' !important;
	position: absolute;
	top:0;
	left:0;
}

/* Style the individual lights */
.fairy-lights-inner span {		
	transform: scale(.9,1) rotate(180deg);
	display: inline-block;
	padding: 20px 10px 0px;
}
	
/* Animate the colors */
.fairy-light-red {
  color: #D22D2D; /* Classic red color */
  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 */
  animation: twinkle 1.5s infinite alternate;
}

.fairy-light-green {
  color: #0F8B0F; /* Traditional green color */
  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 */
  animation: twinkle 1.6s infinite alternate;
}

.fairy-light-yellow {
  color: #FFD700; /* Gold color */
  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 */
  animation: twinkle 1.7s infinite alternate;
}

.fairy-light-blue {
  color: #87CEEB; /* Soft blue, akin to silver/blue */
  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 */
  animation: twinkle 1.8s infinite alternate;
}

@keyframes twinkle {
  0% { opacity: 0.2; }
  100% { opacity: 1; }
}

/* String */
.fairy-lights-inner span:before {
    position: absolute;
    bottom: -5px;
    content: "";
    border: 1px solid #999;
    border-bottom-width: 0;
    border-left-width: 0;
    border-radius: 50%;
    padding: 3px 9px;
    width: 50%;
    border-right-width: 0;
    right: 0%;
    opacity: 0.5;
}
</style>
<?php
}
	
add_action('wp_head', 'divibooster_fairy_lights_css');
}

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 Posts

Fade a Divi Image Module Edge into the Background

Want to create a stylish fade effect on your Divi image module—where one side fades smoothly into the background? With a bit of CSS, you can make any edge (or corner) of the image fade out: top, bottom, left, right, or even diagonally.Fade a Divi Image Module Edge...

Hide the Header and Footer in the Hello Elementor Theme

Removing the default header and footer from your Hello Elementor theme allows for a streamlined and distraction-free website design. This is especially useful when creating unique landing pages, full-width layouts, or custom headers and footers with a page builder. In...

Setting up the Divi Password Box Module

Setting up password protection on a page can help you control access to sensitive or private content in WordPress, allowing only authorized visitors to view certain sections. With the Divi Password Box module, you can replace the plain Divi password form with a fully...

Open Divi Social Media Icons in a New Tab

Ensuring your website's social media icons open in a new browser tab creates a seamless user experience and keeps visitors engaged with your site while allowing them to explore your social media presence. This approach prevents users from navigating away from your...

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...

Random Posts