Code by Day | Explore By Weekend
How To Add A Promo Notification Bar in Divi without plugins Tutorial by Pee-Aye Creative

How To Add A Promo Bar In Divi (Without Plugins)

This tutorial will show you how to easily make a promo notification bar in Divi without plugins on any page or post using the Divi Theme Builder.

#1. Design Your Promo Bar In Divi

Assign Layout In The Divi Theme Builder

The cool part about using Divi and the Theme Builder for your promo bar is that it gives you so much control. Maybe you want a promo bar to appear only on shop pages, or only on blog posts, or only on a specific page. You can! Just assign the pages or post types in the Divi Theme Builder. Go to Divi>Theme Builder. If you already are using the Theme Builder with a header or global header, you will need to work there.

Design The Section

The first you need to do is design your promo bar in the Divi Builder. You can use any combination of Divi Modules that you like, which would typically include a text module, a button, and a close button, which is what we used in our example. You might also want to use an Email Option or a super awesome countdown timer like our new Divi Timer Pro plugin which is an auto-restart and evergreen countdown timer.

Divi Timer Pro Countdown Auto Restart Recurring Evergreen Plugin by Pee Aye Creative 1

#2. Set Up The Divi Promo Bar Close Button

If you want your website visitors to be able to hide your Divi promo bar, we need to add some CSS classes, ID, and code to make the section disappear when a user clicks to close it. The nex three steps in this section are easy to do, and each are important.

Add A Close X Button To The Section

First, you need to add an X close icon to the section. This is easier than you might think. Since Divi comes with a built-in icon font, you can just use the icon code for the X in your layout. So add a Text Module to your section, and place this code in it:

M

add Divi font icon code to close the Divi promo bar

Add CSS ID To Close Icon Text Module

You also need to add a CSS ID to this same Text Module. Go to the Text Module where you placed the icon code and open the settings. In the Advanced tab, open the CSS ID & Classes toggle and place the ID “pa-promo-close” in the CSS ID input field.

add css ID to close the Divi promo bar

Add CSS Class To Section

The last thing we need to do here in the Divi promo bar section is add a CSS class to the section. To do this, go to the section settings to the Advanced tab. Open the CSS ID & Classes toggle and add the class “pa-promo-bar” to the CSS Class input field. 

#3. Add Some Code To Hide The Divi Promo Bar On Click

Javascript

The first piece of code we need to make our Divi promo bar work correctly is some jquery. This is used to hide the promo bar when a site visitor clicks the button to close or hide it. The ID #pa-promo-close is the element that needs to be clicked, which then tells the entire section to hide. So remember when we put this ID in the Text Module with the X icon? That’s the trigger, and when that is clicked, the entire section hides, because of the CSS class we added to the section. Pretty cool, huh?

This code can be placed in Divi>Theme Options>Integrations. Navigate there, and add this in the first code section called “Add code to the < header > of your blog.”

<script>
jQuery(document).ready(function() {  
    jQuery('#pa-promo-close').click(function(){
        jQuery('.pa-promo-bar').hide();
    });  
});
</script>
add javascript code to the integrations areas for the Divi promo bar

CSS

You also need to add a few snippets of CSS. You can do this by going to Divi>Theme Options and pasting the following code in the Custom CSS input area.

/*add mouse pointer when hovering over X icon*/
#pa-promo-close:hover {
	cursor: pointer;
}

/*hide promo bar when use click the X*/
.pa-promo-bar {
	display: none;
}
Add CSS code to the Divi promo bar

PHP

The last set of code is technically optional, but we recommend using it for better user experience. This code is telling the website to keep the promo bar hidden across the site if the user has already clicked to hide it. Once hidden, it will remain hidden for the session, or more specifically, for one hour. After that, if the user visits the site again, the promo bar will be shown again. Adding this helps keep the visitor happy. If they hide it on one page, they may be upset if it appears on the next page. This will help to keep everyone happy.

In order to add this PHP code, you need to have a Divi child theme active on your site. If you don’t already have one, you can download our Free Divi child theme. Copy and paste the following PHP code snippet into the functions.php file of your Divi child theme.

function pa_promo_bar() { 
 
	if(!isset($_COOKIE['pa_promo_bar_shown'])) {
 
		setcookie('pa_promo_bar_shown',  'yes', time()+86400);

		echo '
			<script>
				jQuery(document).ready(function(){
					jQuery(".pa-promo-bar").show();
				});
			</script>
		';
	} 
} 
add_action('wp_head', 'pa_promo_bar');
Add php code to your Divi child theme to close the Divi promo bar
15

Please share this post!

Nelson Lee Miller (aka The Divi Teacher)

Nelson is the owner of Pee-Aye Creative Co in the beautiful state of Pennsylvania. He loves helping small businesses, exploring, building websites with Divi, and teaching others.

Join Our NEW Divi Facebook Group!

The Divi Teacher Logo

Recent Posts

Leave A Response!

Subscribe
Notify of
guest
10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jacques
Jacques
4 months ago

Hi Nelson,

Great tutorial, thanks a lot for sharing this. I have one question: once the site visitor has clicked on the close button and the promo bar disappears, would it be possible to show a small arrow or, any other icon, that would allow the visitor to click on and bring the promo bar back ?

Corine Pettit
Corine Pettit
2 months ago

Hey Nelson!
 
Thanks so much for this tutorial, I’ve had such a hard time finding a promo bar that works with the Theme Builder, so this is much needed. Quick question – is there a way to get the promo bar back to the back-end designer, after closing out? I’ve cleared the cache, but I’m afraid it won’t come back for 24 hours now, per the php code.

Marek
Marek
16 days ago

Hi, Nelson the pa-promo-close is to be put into the CSS-ID or CSS-class or it does not matter? In the video you put it as a class. The other thing, in my case the code &#x4d makes letter M instead of X. Had to replace by &#x58.

Last edited 16 days ago by Marek
Marek
Marek

Hi, thank you for your reply. Funny is that it worked on the video though. However, I am sorry to say the &#x4d still renders M on my browsers (even out of divi builder).

Snímka obrazovky 2020-07-29 o 10.55.54.png
Gil
Gil
10 days ago

Hey, this is a great tutorial. Just curious, in your example, how would you set the header to be fixed at 0,0 after the promo bar is closed? Do you have the header and the promo bar in unique sections and, if so, are they set to default, relative, absolute? Thanks for any additional guidance you can offer.

Gil
Gil

Thanks! I see they are in two sections, but if I set the header to be fixed I have to give it a vertical offset to set it below the promo bar, say 60px. Then when the promo bar section is closed, that space it occupied will remain because the header is fixed with a vertical offset of 60px.In my case I need the header to be fixed so it remains at the top of the screen, I don’t want it to scroll up out of the way. Does that make sense? I apologize if I am totally missing something… Read more »

Shop Our Divi Products!

Child Themes • Plugins • Layouts

Visit The Shop

become partners with Pee Aye Creative

Partner With Us

We are looking for you!

Learn More

Divi Tutorials On YouTube

Subscribe to our helpful Divi videos!

Visit Our Channel

Pin It on Pinterest

0

Your Cart