filmov
tv
Where To Add Custom Code In Divi (CSS, Javascript & PHP)
Показать описание
In this handy guide you will learn exactly where to add custom code like CSS, Javascrip, Jquery, and PHP in your Divi Theme.
Are you wondering where to put those awesome code snippets in Divi? A lot of my tutorials give away a free snippet of CSS, Javascript, Jquery, or PHP. I have found myself repeatedly explaining where to put each snippet, so I thought it would be good to have one centralized article to reference. This guide will help you know where to add custom code in Divi, and I'll also show you the CSS hierarchy as well.
CSS Hierachy (Specificity) In Divi
Before we dive in, let's talk quickly about CSS hierarchy, otherswise know and specificity.
Basically, if you target something with CSS, and there are two or more conflicting CSS rules somewhere on the website that point to the same element, the CSS in certain locations will override the others. It has more power the higher up in hierarchy it is. The browser would get confused otherwise, and needs to follows some rules to determine which one is most specific and therefore which one wins out.
The level of specificity depends where the code is placed in Divi. It would not be very helpful to show you where to add custom code in Divi without showing you why. Here's a list of the CSS hierarchy in Divi, with 1 having the most power and 8 the least:
1. Inline Styles
2. Advanced Tab
3. Code Module
4. Page Settings
5. Theme Options
6. Child Theme
7. Theme Customizer
8. Divi Parent Theme
If your head is spinning in confusion, don't worry. It will make more sense as we go and as you gain hands-on experience, and you will soon understand clearly what each of these are and when to use them.
#1. Inline Styles
Code Languages: CSS, HTML
Inline styles are those that are written directly in the html structure of the page or post. Inline styles have the most importance in code. However, even though these are the most powerful, they should be used only for small, simple changes.
#2. Advanced Tab
Code Languages: CSS
Another form of inline styles, although not as obvious as "inline", is in the Advance tab of any section, row, column, or module. Each have different boxes, and some have quite a lot which are very helpful.
#3. Code Module
Code Languages: CSS, HTML, Javascript
Another option for adding CSS and Javascript is the Divi Code Module., which is perfect for integrating code such as iframes, embed codes, shortcodes, and more.
#4. Page Settings Custom CSS
Code Languages: CSS
My favorite places to add temporary custom code is the in the page settings Advanced tab Custom CSS area. It creates "live view" of the code as you work and edit. Just remember this is temporary, and you should copy and paste this code into your child theme stylesheet or Theme Options custom CSS box when you are done.
#5. Theme Options
Code Languages: CSS, Javascript
The next place to add custom code that affects the entire site at once is the Divi Theme Options. There are several places to add code here at different places.
Custom CSS
You probably have noticed by now that almost every tutorial I write, I mentioned adding the code snippets to the Divi Theme Options Custom CSS box. I say this because it is the easiest and most practical place to add custom CSS, especially for beginners who may not have a Divi child theme.
Javascript (And Jquery)
There's also a handy place in the Theme Options for other types of code, and that is in the Integrations tab. Here you can add code that affects the head or body of the site, similar to a child theme or parent theme. This first box is the perfect place to add all the Javascript and Jquery snippets we give out.
#6. Child Theme
Code Languages: CSS, Javascript, PHP
If you have a child theme installed and active, then I actually recommend putting it there instead. This is the ultimate place to add any time of custom code in Divi.
Custom CSS
Custom PHP
#7. Theme Customizer
Code Languages: CSS
You can also add custom css to the Theme Customizer. You can access this either from Appearance Customize in the backed, or from hovering over yoru website name in the top left corner on the frontend.
#8. Divi Theme
Code Languages: Pretty Much Anything
Last on the list is Divi. This is the worst place to add any kind of custom CSS. Don't do it. If you did, it would be erased and overwritten as soon as Divi has an update. As far as hierarchy goes, this is the weakest place to add custom CSS.
Are you wondering where to put those awesome code snippets in Divi? A lot of my tutorials give away a free snippet of CSS, Javascript, Jquery, or PHP. I have found myself repeatedly explaining where to put each snippet, so I thought it would be good to have one centralized article to reference. This guide will help you know where to add custom code in Divi, and I'll also show you the CSS hierarchy as well.
CSS Hierachy (Specificity) In Divi
Before we dive in, let's talk quickly about CSS hierarchy, otherswise know and specificity.
Basically, if you target something with CSS, and there are two or more conflicting CSS rules somewhere on the website that point to the same element, the CSS in certain locations will override the others. It has more power the higher up in hierarchy it is. The browser would get confused otherwise, and needs to follows some rules to determine which one is most specific and therefore which one wins out.
The level of specificity depends where the code is placed in Divi. It would not be very helpful to show you where to add custom code in Divi without showing you why. Here's a list of the CSS hierarchy in Divi, with 1 having the most power and 8 the least:
1. Inline Styles
2. Advanced Tab
3. Code Module
4. Page Settings
5. Theme Options
6. Child Theme
7. Theme Customizer
8. Divi Parent Theme
If your head is spinning in confusion, don't worry. It will make more sense as we go and as you gain hands-on experience, and you will soon understand clearly what each of these are and when to use them.
#1. Inline Styles
Code Languages: CSS, HTML
Inline styles are those that are written directly in the html structure of the page or post. Inline styles have the most importance in code. However, even though these are the most powerful, they should be used only for small, simple changes.
#2. Advanced Tab
Code Languages: CSS
Another form of inline styles, although not as obvious as "inline", is in the Advance tab of any section, row, column, or module. Each have different boxes, and some have quite a lot which are very helpful.
#3. Code Module
Code Languages: CSS, HTML, Javascript
Another option for adding CSS and Javascript is the Divi Code Module., which is perfect for integrating code such as iframes, embed codes, shortcodes, and more.
#4. Page Settings Custom CSS
Code Languages: CSS
My favorite places to add temporary custom code is the in the page settings Advanced tab Custom CSS area. It creates "live view" of the code as you work and edit. Just remember this is temporary, and you should copy and paste this code into your child theme stylesheet or Theme Options custom CSS box when you are done.
#5. Theme Options
Code Languages: CSS, Javascript
The next place to add custom code that affects the entire site at once is the Divi Theme Options. There are several places to add code here at different places.
Custom CSS
You probably have noticed by now that almost every tutorial I write, I mentioned adding the code snippets to the Divi Theme Options Custom CSS box. I say this because it is the easiest and most practical place to add custom CSS, especially for beginners who may not have a Divi child theme.
Javascript (And Jquery)
There's also a handy place in the Theme Options for other types of code, and that is in the Integrations tab. Here you can add code that affects the head or body of the site, similar to a child theme or parent theme. This first box is the perfect place to add all the Javascript and Jquery snippets we give out.
#6. Child Theme
Code Languages: CSS, Javascript, PHP
If you have a child theme installed and active, then I actually recommend putting it there instead. This is the ultimate place to add any time of custom code in Divi.
Custom CSS
Custom PHP
#7. Theme Customizer
Code Languages: CSS
You can also add custom css to the Theme Customizer. You can access this either from Appearance Customize in the backed, or from hovering over yoru website name in the top left corner on the frontend.
#8. Divi Theme
Code Languages: Pretty Much Anything
Last on the list is Divi. This is the worst place to add any kind of custom CSS. Don't do it. If you did, it would be erased and overwritten as soon as Divi has an update. As far as hierarchy goes, this is the weakest place to add custom CSS.
Комментарии